Class: Dam::TypeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dam/activity.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ TypeProxy

Returns a new instance of TypeProxy.



8
9
10
# File 'lib/dam/activity.rb', line 8

def initialize(type)
  @type = type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, arg = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dam/activity.rb', line 12

def method_missing(meth, arg=nil, &block)
  
  # the attribute can either be a static value, or a block to be evaluated, not both
  raise ArgumentError unless (!arg.nil? ^ block_given?)
  
  if block_given?
    @type.add_attribute(:name => meth, :block => block)
  else
    @type.add_attribute(:name => meth, :value => arg)
  end
  
end