class Wongi::Engine::DSL::Action::SimpleAction

Public Class Methods

new(action = nil, *args, &block) click to toggle source
# 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

Public Instance Methods

deexecute(token) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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