Module: Replay::EventDeclarations
- Defined in:
- lib/replay/event_declarations.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
19
20
21
|
# File 'lib/replay/event_declarations.rb', line 19
def method_missing(name, *args)
declare_event(self, name, args.first)
end
|
Class Method Details
.included(base) ⇒ Object
3
4
5
|
# File 'lib/replay/event_declarations.rb', line 3
def self.included(base)
base.extend(Replay::Events)
end
|
Instance Method Details
#declare_event(base, name, props) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/replay/event_declarations.rb', line 23
def declare_event(base, name, props)
klass = Class.new do
include Replay::EventDecorator
values do
props.keys.each do |prop|
attribute prop, props[prop]
end
end
end
base.const_set name, klass
end
|
#included(base) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/replay/event_declarations.rb', line 7
def included(base)
self.constants.each do |c|
base.const_set(c, const_get(c).dup)
klass = base.const_get(c)
base.class_eval do
define_method c do |props|
klass.new props
end
end
end
end
|