Back to Groups
Development

Ruby: internal tools engineer

Ruby 3.2 standard library. Normalize import records, reject ambiguous identifiers, and collect row-level validation failures. Review names and integration points before use.

workflowsstdlibrubycoderuby-developer
RO
robinf
0likes12snippets

Try it here

Loading snippet…

Your typing stays in this tab. Nothing is saved or sent.
Snippets (12)
;rb-utc-parse
Require an offset when parsing a timestamp
require 'date' def utc_timestamp(text) format = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(
;rb-csv-rows
Validate a CSV import before mapping rows
require 'csv' def csv_records(text, required:) rows = CSV.parse(text, headers: false) headers =
;rb-measure
Time a block without changing its result
def measured started = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield elapsed
;rb-index
Index records and reject duplicate IDs
def index_unique(records, key: :id) records.each_with_object({}) do |record, index| id = recor
;rb-env-required
Read a required environment value
def required_env(name) value = ENV.fetch(name) do raise KeyError, "Missing environment variabl
;rb-options
Convert only allowed string option names
def service_options(input) allowed = { 'limit' => :limit, 'cursor' => :cursor, 'include_archived'
;rb-json-records
Accept a bounded JSON record batch
require "json" def json_records(text, max_records: 10_000) unless max_records.is_a?(Integer) && (
;rb-page-result
Immutable pagination result wrapper
PageResult = Struct.new(:items, :next_cursor, keyword_init: true) do def initialize(items:, next_c
;rb-row-key
Normalize identifiers before duplicate checks
def import_key(raw) unless raw.is_a?(String) && raw.bytesize <= 256 && raw.valid_encoding? rai
;rb-query-url
Build an HTTPS URL with encoded query values
require 'uri' def query_url(base, pairs) uri = URI.parse(base) unless uri.is_a?(URI::HTTPS) &&
;rb-integer-column
Coerce one integer import column with bounds
def integer_column(row, column, min:, max:) unless min.is_a?(Integer) && max.is_a?(Integer) && min
;rb-validate-batch
Collect row failures before writing an import
def validate_batch(rows, max_errors: 50) unless rows.is_a?(Array) && rows.length <= 10_000 &&