Sha256: 52182d0bb0abd27de2a4afc1fc180def2fb68e6962897cd7b4d64157f396294b

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

require 'custom_attributes/custom_attributes_api_helper'

module CustomAttributes
  module ControllerHelper
    module Customizable
      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

      def self.all_values(customizable)
        return customizable.custom_field_values
      end

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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
create_custom_attributes-0.5.2 lib/custom_attributes/api/custom_attributes_controller_helper.rb
create_custom_attributes-0.5.0 lib/custom_attributes/api/custom_attributes_controller_helper.rb