Module: CustomAttributes::ActsAsCustomValue::InstanceMethods

Defined in:
lib/custom_attributes/acts_as/acts_as_custom_value.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


41
42
43
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 41

def required?
  custom_field.is_required?
end

#to_sObject



45
46
47
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 45

def to_s
  value.to_s
end

#true?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 33

def true?
  value == '1'
end

#valueObject



27
28
29
30
31
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 27

def value
  return read_attribute(:value) if new_record?

  read_attribute(:value) || custom_field.try(:default)
end

#visible?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/custom_attributes/acts_as/acts_as_custom_value.rb', line 37

def visible?
  custom_field.visible?
end