Class: Remailer::Interpreter::StateProxy
- Inherits:
-
Object
- Object
- Remailer::Interpreter::StateProxy
- Defined in:
- lib/remailer/interpreter/state_proxy.rb
Instance Method Summary collapse
-
#default(&block) ⇒ Object
Defines a default behavior that will trigger in the event no interpreter definition was triggered first.
-
#enter(&block) ⇒ Object
Defines a block that will execute when the state is entered.
-
#initialize(options, &block) ⇒ StateProxy
constructor
Creates a new state proxy object with a particular set of options.
-
#interpret(response, &block) ⇒ Object
Defines an interpreter block that will execute if the given response condition is met.
-
#leave(&block) ⇒ Object
Defines a block that will execute when the state is left.
-
#parse(spec = nil, &block) ⇒ Object
Defines a parser specification.
-
#terminate(&block) ⇒ Object
Terminates the interpreter after this state has been entered.
Constructor Details
#initialize(options, &block) ⇒ StateProxy
Creates a new state proxy object with a particular set of options. An optional supplied block can be used to perform additional configuration, and will be evaluated within the context of this new object.
9 10 11 12 13 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 9 def initialize(, &block) @options = instance_eval(&block) if (block_given?) end |
Instance Method Details
#default(&block) ⇒ Object
Defines a default behavior that will trigger in the event no interpreter definition was triggered first.
33 34 35 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 33 def default(&block) (@options[:default] ||= [ ]) << block end |
#enter(&block) ⇒ Object
Defines a block that will execute when the state is entered.
21 22 23 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 21 def enter(&block) (@options[:enter] ||= [ ]) << block end |
#interpret(response, &block) ⇒ Object
Defines an interpreter block that will execute if the given response condition is met.
27 28 29 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 27 def interpret(response, &block) (@options[:interpret] ||= [ ]) << [ response, block ] end |
#leave(&block) ⇒ Object
Defines a block that will execute when the state is left.
38 39 40 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 38 def leave(&block) (@options[:leave] ||= [ ]) << block end |
#parse(spec = nil, &block) ⇒ Object
Defines a parser specification.
16 17 18 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 16 def parse(spec = nil, &block) @options[:parser] = Remailer::Interpreter.create_parser_for_spec(spec, &block) end |
#terminate(&block) ⇒ Object
Terminates the interpreter after this state has been entered. Will execute a block if one is supplied.
44 45 46 47 48 49 50 |
# File 'lib/remailer/interpreter/state_proxy.rb', line 44 def terminate(&block) @options[:terminate] ||= [ ] if (block_given?) @options[:terminate] << block end end |