Module: NoBrainer::Boolean::NoBrainerExtensions
- Included in:
- NoBrainer::Boolean
- Defined in:
- lib/no_brainer/document/types/boolean.rb
Constant Summary collapse
- InvalidType =
NoBrainer::Error::InvalidType
Instance Method Summary collapse
- #nobrainer_cast_user_to_model(value) ⇒ Object
- #nobrainer_field_defined(model, attr, options = {}) ⇒ Object
- #nobrainer_field_undefined(model, attr, options = {}) ⇒ Object
Instance Method Details
#nobrainer_cast_user_to_model(value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/no_brainer/document/types/boolean.rb', line 10 def nobrainer_cast_user_to_model(value) case value when TrueClass then true when FalseClass then false when String, Integer value = value.to_s.strip.downcase return true if value.in? %w(true yes t 1) return false if value.in? %w(false no f 0) raise InvalidType else raise InvalidType end end |
#nobrainer_field_defined(model, attr, options = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/no_brainer/document/types/boolean.rb', line 23 def nobrainer_field_defined(model, attr, ={}) model.inject_in_layer :types do define_method("#{attr}?") { !!read_attribute(attr) } end end |
#nobrainer_field_undefined(model, attr, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/no_brainer/document/types/boolean.rb', line 29 def nobrainer_field_undefined(model, attr, ={}) model.inject_in_layer :types do remove_method("#{attr}?") end end |