Module: HasOptions

Defined in:
lib/adva/active_record/has_options.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#has_option(*names) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/adva/active_record/has_options.rb', line 2

def has_option(*names)
  unless respond_to?(:option_definitions)
    include InstanceMethods
    class_inheritable_accessor :option_definitions
    self.option_definitions = {}
    serialize :options
  end

  definition = names.extract_options!
  names.map(&:to_sym).each do |name|
    self.option_definitions[name] = definition

    class_eval "def \#{name}\nself.options ||= {}\noptions.key?(:\#{name}) ? options[:\#{name}] : option_default(:\#{name})\nend\n# alias \#{name}_before_type_cast \#{name}\n\ndef \#{name}=(value)\noptions_will_change!\nself.options ||= {}\noptions[:\#{name}] = option_type_cast(:\#{name}, value)\nend\n", __FILE__, __LINE__
  end
end