Sha256: 02c43bacff5887fe16e77c3e174f669c6eafe2a4207ccdcc804f22aa0cd59095

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

class Dhatu::PromotionAttribute < Dhatu::ApplicationRecord

  # Set Table Name
  self.table_name = "dhatu_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

9 entries across 9 versions & 1 rubygems

Version Path
dhatu-0.3.9.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.8.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.7.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.6.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.5.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.4.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.3.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.2.pre.materialize app/models/dhatu/promotion_attribute.rb
dhatu-0.3.1.pre.materialize app/models/dhatu/promotion_attribute.rb