Class: CustomAttributes::CustomFieldValue
- Inherits:
-
Object
- Object
- CustomAttributes::CustomFieldValue
- Defined in:
- lib/custom_attributes/custom_field_value.rb
Overview
Decorator for CustomValues
Instance Attribute Summary collapse
-
#custom_field ⇒ Object
Returns the value of attribute custom_field.
-
#customizable ⇒ Object
Returns the value of attribute customizable.
-
#value ⇒ Object
Returns the value of attribute value.
-
#value_was ⇒ Object
Returns the value of attribute value_was.
Instance Method Summary collapse
- #custom_field_id ⇒ Object
- #custom_field_slug ⇒ Object
-
#initialize(attributes = {}) ⇒ CustomFieldValue
constructor
A new instance of CustomFieldValue.
- #required? ⇒ Boolean
- #serializable_hash(options = nil) ⇒ Object
- #to_s ⇒ Object
- #true? ⇒ Boolean
- #validate_value ⇒ Object
- #value_present? ⇒ Boolean
- #visible? ⇒ Boolean
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_field ⇒ Object
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 |
#customizable ⇒ Object
Returns the value of attribute customizable.
4 5 6 |
# File 'lib/custom_attributes/custom_field_value.rb', line 4 def customizable @customizable end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/custom_attributes/custom_field_value.rb', line 4 def value @value end |
#value_was ⇒ Object
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_id ⇒ Object
12 13 14 |
# File 'lib/custom_attributes/custom_field_value.rb', line 12 def custom_field_id custom_field.id end |
#custom_field_slug ⇒ Object
16 17 18 |
# File 'lib/custom_attributes/custom_field_value.rb', line 16 def custom_field_slug custom_field.slug end |
#required? ⇒ 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( = nil) { custom_field_id: self.custom_field_id, value: self.value }.as_json end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/custom_attributes/custom_field_value.rb', line 32 def to_s value.to_s end |
#true? ⇒ Boolean
20 21 22 |
# File 'lib/custom_attributes/custom_field_value.rb', line 20 def true? value == '1' end |
#validate_value ⇒ Object
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 || customizable.errors.add(:base, custom_field.name + ' ' + ) end end |
#value_present? ⇒ 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
24 25 26 |
# File 'lib/custom_attributes/custom_field_value.rb', line 24 def visible? custom_field.visible? end |