Class: Wongi::Engine::DSL::Action::SimpleAction
- Inherits:
-
Base
- Object
- Base
- Wongi::Engine::DSL::Action::SimpleAction
show all
- Defined in:
- lib/wongi-engine/dsl/action/simple_action.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #production, #rete, #rule
Instance Method Summary
collapse
Methods included from CoreExt
included
Constructor Details
#initialize(action = nil, *args, &block) ⇒ SimpleAction
Returns a new instance of SimpleAction.
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/wongi-engine/dsl/action/simple_action.rb', line 4
def initialize action = nil, *args, &block
@args = args
case action
when Class
@action = @deaction = @reaction = action.new *args, &block
when Hash
@action = instance_or_proc action[:activate]
@deaction = instance_or_proc action[:deactivate]
@reaction = instance_or_proc action[:reactivate]
end
@action ||= block
end
|
Instance Method Details
#deexecute(token) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/wongi-engine/dsl/action/simple_action.rb', line 28
def deexecute token
return unless @deaction
if @deaction.is_a?( Proc ) || @deaction.respond_to?( :to_proc )
rete.instance_exec token, &@deaction
elsif @deaction.respond_to? :call
@deaction.call token
elsif @deaction.respond_to? :deexecute
@deaction.execute token
end
end
|
#execute(token) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/wongi-engine/dsl/action/simple_action.rb', line 17
def execute token
return unless @action
if @action.is_a?( Proc ) || @action.respond_to?( :to_proc )
rete.instance_exec token, &@action
elsif @action.respond_to? :call
@action.call token
elsif @action.respond_to? :execute
@action.execute token
end
end
|
#instance_or_proc(thing) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/wongi-engine/dsl/action/simple_action.rb', line 50
def instance_or_proc thing
case thing
when Class
thing.new
when Proc
thing
end
end
|
#reexecute(token, newtoken) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/wongi-engine/dsl/action/simple_action.rb', line 39
def reexecute token, newtoken
return unless @reaction
if @reaction.is_a?( Proc ) || @reaction.respond_to?( :to_proc )
rete.instance_exec token, newtoken, &@reaction
elsif @reaction.respond_to? :call
@reaction.call token, newtoken
elsif @reaction.respond_to? :reexecute
@reaction.execute token, newtoken
end
end
|