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 <<-EOF

      def #{name}(value = nil, opts = {})
        obj = #{clazz}.new(value, opts)
        yield obj if block_given?
        self.#{store} << obj
        self
      end

      EOF
    end

  end

end