Class: CloudBuilder::DSLOpenStruct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/cloud_builder/dslostruct.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloud_builder/dslostruct.rb', line 14

def method_missing(mid, *args)
  mname = mid.id2name
  len = args.length
  if mname.chomp!('=')
    if len != 1
      raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
    end
    modifiable[new_ostruct_member(mname)] = args[0]
  elsif len == 0
    if @table.has_key? mid
      @table[mid]
    else
      raise NameError, "undefined property #{mid} for #{self}", caller(1)
    end
  else
    raise NoMethodError, "undefined method `#{mid}' for #{self}", caller(1)
  end
end

Instance Method Details

#get_att(name, att) ⇒ Object



10
11
12
# File 'lib/cloud_builder/dslostruct.rb', line 10

def get_att(name, att)
  Reference::Attribute.new(name, att)
end

#ref(name) ⇒ Object



6
7
8
# File 'lib/cloud_builder/dslostruct.rb', line 6

def ref(name)
  Reference.new(name)
end