Sha256: 7cb87c4d49b43e5c0436bc3dafc0a7fd80667bf299612285e5024b3ec0c720e8

Contents?: true

Size: 904 Bytes

Versions: 4

Compression:

Stored size: 904 Bytes

Contents

# A simple class to manage menu options, usable by other classes to build their menus.
#
class MenuOption < ActiveRecord::Base
  KEYS = [
    'Deal Category',
    'Email',
    'Instant Messaging Handle',
    'Phone Number',
    #'Task Category',
    #'Task Status',
    'Website'
  ].freeze

  validates :value, :presence  => true
  validates :key,   :presence  => true, :inclusion => { :in => KEYS, :allow_blank => true }

  acts_as_list :scope => 'menu_options.key = \"#{key}\"'

  scope :options_for, lambda {|key| where(:key => key) }

  ##
  # A direct SQL selection of values for a given key
  #
  #   MenuOption.fetch('Email') #=> ['Personal','Work']
  #
  # === Parameters
  #
  # [key (String)] The key for the assocated menu options.
  #
  def self.fetch_values(key)
    connection.send(:select_values, options_for(key).order(:position).project('value').to_sql, 'Menu Option Select')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
e9_crm-0.1.6 app/models/menu_option.rb
e9_crm-0.1.5 app/models/menu_option.rb
e9_crm-0.1.4 app/models/menu_option.rb
e9_crm-0.1.1 app/models/menu_option.rb