Class: FilterParam::Field
- Inherits:
-
Object
- Object
- FilterParam::Field
- Defined in:
- lib/filter_param/field.rb
Constant Summary collapse
- TYPES =
%i[boolean string integer decimal date datetime].freeze
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
- #actual_name ⇒ Object
- #allow_operator?(operator) ⇒ Boolean
-
#initialize(name, type, options = {}) ⇒ Field
constructor
A new instance of Field.
- #transform_value(value) ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ Field
Returns a new instance of Field.
7 8 9 10 11 12 |
# File 'lib/filter_param/field.rb', line 7 def initialize(name, type, = {}) @name = name @type = field_type(type) @rename = field_rename([:rename]) @value_transformer = [:value] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/filter_param/field.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/filter_param/field.rb', line 5 def type @type end |
Instance Method Details
#actual_name ⇒ Object
20 21 22 |
# File 'lib/filter_param/field.rb', line 20 def actual_name rename.presence || name end |
#allow_operator?(operator) ⇒ Boolean
24 25 26 |
# File 'lib/filter_param/field.rb', line 24 def allow_operator?(operator) true end |
#transform_value(value) ⇒ Object
14 15 16 17 18 |
# File 'lib/filter_param/field.rb', line 14 def transform_value(value) return value if value_transformer.blank? value_transformer.call(value) end |