Module: Babushka::AcceptsListFor::ClassMethods

Defined in:
lib/babushka/accepts_list_for.rb

Instance Method Summary collapse

Instance Method Details

#accepts_list_for(method_name, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/babushka/accepts_list_for.rb', line 8

def accepts_list_for method_name, *args
  opts = {:type => 'list'}.merge args.extract_options!
  default = args.shift

  file, line = caller.first.split(':', 2)
  line = line.to_i

  module_eval "    def \#{method_name} *args, &block\n      if !args.empty? && !block.nil?\n        raise ArgumentError, \"You can supply arguments or a block, but not both.\"\n      elsif args.empty? && block.nil?\n        \#{opts[:type]}_for \#{method_name.inspect}, \#{default.inspect}\n      else\n        store_\#{opts[:type]}_for \#{method_name.inspect}, block || [*args].flatten, \#{opts[:choose_with].inspect}\n        self\n      end\n    end\n  LOL\nend\n", file, line