Class: WiseGopher::Param
- Inherits:
-
Object
- Object
- WiseGopher::Param
- Defined in:
- lib/wise_gopher/param.rb
Overview
Register query’s params and build query’s bind variables
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #build_bind(value) ⇒ Object
-
#initialize(name, type_symbol, transform = nil) ⇒ Param
constructor
A new instance of Param.
- #type ⇒ Object
Constructor Details
#initialize(name, type_symbol, transform = nil) ⇒ Param
Returns a new instance of Param.
8 9 10 11 12 |
# File 'lib/wise_gopher/param.rb', line 8 def initialize(name, type_symbol, transform = nil) @name = name.to_s.freeze @type_symbol = type_symbol @transform = transform&.to_proc end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/wise_gopher/param.rb', line 6 def name @name end |
Instance Method Details
#build_bind(value) ⇒ Object
14 15 16 17 18 |
# File 'lib/wise_gopher/param.rb', line 14 def build_bind(value) prepared_value = @transform ? transform_value(value) : value ActiveRecord::Relation::QueryAttribute.new(name, prepared_value, type) end |
#type ⇒ Object
20 21 22 |
# File 'lib/wise_gopher/param.rb', line 20 def type @type ||= ActiveRecord::Type.lookup type_symbol end |