Sha256: 33b0bbb732f76e628a2ea6e2888a2ceacfa15aa07f45337b3cc1b46d361b9f19
Contents?: true
Size: 1.75 KB
Versions: 13
Compression:
Stored size: 1.75 KB
Contents
class Dhatu::PromotionAttribute < Dhatu::ApplicationRecord # Set Table Name self.table_name = "promotion_attributes" # Including the State Machine Methods include Publishable attr_accessor :values_string # Data Type could be text, integer, date, list_drop_down (Select from a List), list_radio_button (Choose one) & boolean (Checkbox) DATA_TYPES = {"Text" => "text", "Integer" => "integer", "Date" => "date", "List (Drop Down)" => "list_drop_down", "List (Radio Button)" => "list_radio_button", "Boolean (Checkbox)" => "boolean"} DATA_TYPES_REVERSE = {"text" => "Text", "integer" => "Integer", "date" => "Date", "list_drop_down" => "List (Drop Down)", "list_radio_button" => "List (Radio Button)", "boolean" => "Boolean (Checkbox)"} # Validations validate_string :name, mandatory: true, min_length: 2, max_length: 128, format: /.*/i validates :data_type, :presence=> true, :inclusion => {:in => DATA_TYPES.values, :presence_of => :data_type, :message => "%{value} is not a valid data type" } # Associations belongs_to :promotion # Serializers serialize :values, Array # Callbacks before_validation :convert_string_values_to_array # ------------------ # Instance Methods # ------------------ # Other Methods # ------------------ def display_name self.name end def display_data_type DATA_TYPES_REVERSE[self.data_type] end def convert_string_values_to_array self.values = self.values_string.split(",") if self.values_string end def set_string_values self.values_string = self.values.join(",") if ["list_drop_down", "list_radio_button", ""].include?(self.data_type.to_s) end # Permission Methods # ------------------ def can_be_edited? true end def can_be_deleted? true end end
Version data entries
13 entries across 13 versions & 1 rubygems