Class: BooleanField
- Defined in:
- lib/yodel/models/core/fields/boolean_field.rb
Constant Summary
Constants inherited from Field
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #default_input_type ⇒ Object
- #from_json(value, record) ⇒ Object
- #json_action(action, value, record) ⇒ Object
Methods inherited from Field
#display?, field_from_type, from_options, #include_in_search_keywords?, #index?, #inherited?, #initialize, #method_missing, #numeric?, #required?, #searchable?, #strip_nil?, #to_json, #to_str, #typecast, #unique?, #untypecast, #validate
Constructor Details
This class inherits a constructor from Field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Field
Instance Method Details
#default_input_type ⇒ Object
2 3 4 |
# File 'lib/yodel/models/core/fields/boolean_field.rb', line 2 def default_input_type :radio end |
#from_json(value, record) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/yodel/models/core/fields/boolean_field.rb', line 17 def from_json(value, record) if value == 'true' true elsif value == 'false' false else !!value end end |
#json_action(action, value, record) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/yodel/models/core/fields/boolean_field.rb', line 6 def json_action(action, value, record) case action when 'set' record.set_raw(name, !!value) when 'toggle' record.set_raw(name, !record.get(name)) end record.changed!(name) end |