Module: ApiDef::Support::AttrUnoArray

Included in:
Element
Defined in:
lib/api_def/support/attr_uno_array.rb

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



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
# File 'lib/api_def/support/attr_uno_array.rb', line 3

def self.included(mod)

  mod.class_eval do

    def self.attr_uno_array(name, opts)
      clazz = opts[:class]
      raise "Please specify a class" unless clazz
      store = opts[:store] || (name.to_s + "s")

      self.attr_array store
      self.class_eval "\n      def \#{name}(value = nil, opts = {})\n        obj = \#{clazz}.new(value, opts)\n        yield obj if block_given?\n        self.\#{store} << obj\n        self\n      end\n\n      EOF\n    end\n\n  end\n\nend\n"