Module: CustomAttributes::ControllerHelper::Customizable

Defined in:
lib/custom_attributes/api/custom_attributes_controller_helper.rb

Class Method Summary collapse

Class Method Details

.all_available_fields(customizable_type) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/custom_attributes/api/custom_attributes_controller_helper.rb', line 6

def self.all_available_fields(customizable_type)
  customizable = customizable_type
  if customizable_type.is_a? String
    customizable = get_customizable_class_or_fail(customizable_type).new
  end

  customizable.available_custom_fields
end

.all_values(customizable) ⇒ Object



15
16
17
# File 'lib/custom_attributes/api/custom_attributes_controller_helper.rb', line 15

def self.all_values(customizable)
  customizable.custom_field_values
end

.update_field_value(customizable, field_id, value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/custom_attributes/api/custom_attributes_controller_helper.rb', line 23

def self.update_field_value(customizable, field_id, value)
  to_change = { field_id => value }
  customizable.custom_field_values = to_change
  customizable.save!

  customizable.custom_value_for(field_id)
end

.value_by_field_id(customizable, field_id) ⇒ Object



19
20
21
# File 'lib/custom_attributes/api/custom_attributes_controller_helper.rb', line 19

def self.value_by_field_id(customizable, field_id)
  customizable.populated_custom_field_value(field_id)
end