Sha256: cb5e80b1e7c27decdb65c6c63009ee90f082c09a58bce955f4a00ec62eb3ab34
Contents?: true
Size: 802 Bytes
Versions: 2
Compression:
Stored size: 802 Bytes
Contents
# frozen_string_literal: true module WiseGopher # Register query's params and build query's bind variables class Param attr_reader :name def initialize(name, type_symbol, transform = nil) @name = name.to_s.freeze @type_symbol = type_symbol @transform = transform&.to_proc end def build_bind(value) prepared_value = @transform ? transform_value(value) : value ActiveRecord::Relation::QueryAttribute.new(name, prepared_value, type) end def type @type ||= ActiveRecord::Type.lookup type_symbol end private attr_reader :type_symbol def transform_value(value) case @transform.arity when 0 then value.instance_exec(&@transform) else value.instance_eval(&@transform) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wise_gopher-0.3.2 | lib/wise_gopher/param.rb |
wise_gopher-0.2.2 | lib/wise_gopher/param.rb |