Class: CustomAttributes::CustomFieldValue

Inherits:
Object
  • Object
show all
Defined in:
lib/custom_attributes/custom_field_value.rb

Overview

Decorator for CustomValues

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CustomFieldValue

Returns a new instance of CustomFieldValue.



6
7
8
9
10
# File 'lib/custom_attributes/custom_field_value.rb', line 6

def initialize(attributes = {})
  attributes.each do |name, v|
    send "#{name}=", v
  end
end

Instance Attribute Details

#custom_fieldObject

Returns the value of attribute custom_field.



4
5
6
# File 'lib/custom_attributes/custom_field_value.rb', line 4

def custom_field
  @custom_field
end

#customizableObject

Returns the value of attribute customizable.



4
5
6
# File 'lib/custom_attributes/custom_field_value.rb', line 4

def customizable
  @customizable
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/custom_attributes/custom_field_value.rb', line 4

def value
  @value
end

#value_wasObject

Returns the value of attribute value_was.



4
5
6
# File 'lib/custom_attributes/custom_field_value.rb', line 4

def value_was
  @value_was
end

Instance Method Details

#custom_field_idObject



12
13
14
# File 'lib/custom_attributes/custom_field_value.rb', line 12

def custom_field_id
  custom_field.id
end

#custom_field_slugObject



16
17
18
# File 'lib/custom_attributes/custom_field_value.rb', line 16

def custom_field_slug
  custom_field.slug
end

#required?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/custom_attributes/custom_field_value.rb', line 28

def required?
  custom_field.is_required?
end

#serializable_hash(options = nil) ⇒ Object



36
37
38
# File 'lib/custom_attributes/custom_field_value.rb', line 36

def serializable_hash(options = nil)
  { custom_field_id: self.custom_field_id, value: self.value }.as_json
end

#to_sObject



32
33
34
# File 'lib/custom_attributes/custom_field_value.rb', line 32

def to_s
  value.to_s
end

#true?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/custom_attributes/custom_field_value.rb', line 20

def true?
  value == '1'
end

#validate_valueObject



52
53
54
55
56
# File 'lib/custom_attributes/custom_field_value.rb', line 52

def validate_value
  custom_field.validate_custom_value(self).each do |message|
    customizable.errors.add(:base, custom_field.name + ' ' + message)
  end
end

#value_present?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/custom_attributes/custom_field_value.rb', line 44

def value_present?
  if value.is_a?(Array)
    value.any?(&:present?)
  else
    value.present?
  end
end

#visible?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/custom_attributes/custom_field_value.rb', line 24

def visible?
  custom_field.visible?
end