Class: Dam::ActivityType

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ ActivityType

Instance methods



51
52
53
54
55
56
57
58
# File 'lib/dam/activity.rb', line 51

def initialize(name, &block)
  @attributes = {}
  @name = name
  
  proxy = TypeProxy.new(self)
  
  proxy.instance_eval(&block)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



34
35
36
# File 'lib/dam/activity.rb', line 34

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'lib/dam/activity.rb', line 35

def name
  @name
end

Class Method Details

.lookup(type) ⇒ Object



45
46
47
48
# File 'lib/dam/activity.rb', line 45

def self.lookup(type)
  @activity_types ||= {}
  @activity_types[type]
end

.register(type, act) ⇒ Object

Class methods



38
39
40
41
42
43
# File 'lib/dam/activity.rb', line 38

def self.register(type, act)
  @activity_types ||= {}
  @activity_types[type] = act

  act
end

Instance Method Details

#add_attribute(params = {}) ⇒ Object



60
61
62
63
# File 'lib/dam/activity.rb', line 60

def add_attribute(params = {})
  @attributes[params[:name].to_s] = params[:value] || params[:block]
  self
end

#apply(params = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dam/activity.rb', line 65

def apply(params = {})
  context = Context.new(params)
  evaluated_attributes = {}
  @attributes.each_pair do |attribute, value| 
    evaluated_attributes[attribute.to_s] = if value.respond_to? :call
      context.instance_eval(&value)
    else
      value
    end
  end
  
  Activity.new(self.name, evaluated_attributes)
end