Module: Hashdown::SelectOptions

Defined in:
lib/hashdown/select_options.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Method Summary collapse

Instance Method Details

#selectable(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hashdown/select_options.rb', line 3

def selectable(*args)
  unless respond_to?(:select_options)
    extend ClassMethods
    include InstanceMethods

    after_save    :clear_select_options_cache
    after_destroy :clear_select_options_cache

    class << self
      attr_accessor :select_options_options
    end
  end

  options = args.pop if args.last.is_a?(Hash)
  options ||= {}

  options[:label] ||= args.shift || :name
  options[:value] ||= args.shift || :id

  self.select_options_options = options
end