remailer 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/remailer/interpreter.rb +5 -0
- data/remailer.gemspec +1 -1
- data/test/helper.rb +1 -1
- data/test/unit/remailer_interpreter_test.rb +16 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/remailer/interpreter.rb
CHANGED
@@ -150,9 +150,14 @@ class Remailer::Interpreter
|
|
150
150
|
# include:
|
151
151
|
# * :delegate => Which object to use as a delegate, if applicable.
|
152
152
|
# * :state => What the initial state should be. The default is :initalized
|
153
|
+
# If a block is supplied, the interpreter object is supplied as an argument
|
154
|
+
# to give the caller an opportunity to perform any initial configuration
|
155
|
+
# before the first state is entered.
|
153
156
|
def initialize(options = nil)
|
154
157
|
@delegate = (options and options[:delegate])
|
155
158
|
|
159
|
+
yield(self) if (block_given?)
|
160
|
+
|
156
161
|
enter_state(options && options[:state] || self.class.initial_state)
|
157
162
|
end
|
158
163
|
|
data/remailer.gemspec
CHANGED
data/test/helper.rb
CHANGED
@@ -101,6 +101,10 @@ class ExampleInterpreter < Remailer::Interpreter
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
class InterpreterWithAccessor < Remailer::Interpreter
|
105
|
+
attr_accessor :example
|
106
|
+
end
|
107
|
+
|
104
108
|
class RemailerInterpreterTest < Test::Unit::TestCase
|
105
109
|
def test_default_state
|
106
110
|
assert_equal [ :initialized, :terminated ], Remailer::Interpreter.states_defined.collect { |s| s.to_s }.sort.collect { |s| s.to_sym }
|
@@ -283,4 +287,16 @@ class RemailerInterpreterTest < Test::Unit::TestCase
|
|
283
287
|
assert interpreter.error.index(':initialized')
|
284
288
|
assert interpreter.error.index(':invalid')
|
285
289
|
end
|
290
|
+
|
291
|
+
def test_new_with_block
|
292
|
+
interpreter = InterpreterWithAccessor.new
|
293
|
+
|
294
|
+
assert_equal nil, interpreter.example
|
295
|
+
|
296
|
+
interpreter = InterpreterWithAccessor.new do |interpreter|
|
297
|
+
interpreter.example = 'example'
|
298
|
+
end
|
299
|
+
|
300
|
+
assert_equal 'example', interpreter.example
|
301
|
+
end
|
286
302
|
end
|