Module: CustomAttributes::ActsAsCustomValue::InstanceMethods
- Defined in:
- lib/custom_attributes/acts_as/acts_as_custom_value.rb
Instance Method Summary collapse
- #initialize(attributes = nil, *args) ⇒ Object
- #required? ⇒ Boolean
- #to_s ⇒ Object
- #true? ⇒ Boolean
- #value ⇒ Object
- #visible? ⇒ Boolean
Instance Method Details
#initialize(attributes = nil, *args) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 20 def initialize(attributes = nil, *args) super if new_record? && custom_field && !attributes.key?(:value) self.value ||= custom_field.default end end |
#required? ⇒ Boolean
44 45 46 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 44 def required? custom_field.is_required? end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 48 def to_s value.to_s end |
#true? ⇒ Boolean
36 37 38 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 36 def true? value == '1' end |
#value ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 27 def value field_value = read_attribute(:value) || nil field_value = nil if field_value.nil? || ( !field_value.is_a?(Numeric) && field_value.empty? ) return field_value if new_record? field_value || custom_field.try(:default) end |
#visible? ⇒ Boolean
40 41 42 |
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 40 def visible? custom_field.visible? end |