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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build_bind(value) ⇒ Object
-
#initialize(name, type_symbol, transform = nil) ⇒ Param
constructor
A new instance of Param.
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 = ActiveRecord::Type.lookup 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 |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/wise_gopher/param.rb', line 6 def type @type 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 |