james 0.0.11-universal-darwin-10 → 0.0.12-universal-darwin-10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/james/state_api.rb +8 -2
- data/lib/james/state_internals.rb +3 -0
- data/lib/james/visitor.rb +4 -1
- data/spec/integration/test_dialogue_spec.rb +0 -16
- data/spec/lib/james/dialogue_spec.rb +24 -0
- metadata +2 -2
data/lib/james/state_api.rb
CHANGED
@@ -38,8 +38,8 @@ module James
|
|
38
38
|
# Example for staying in the same state:
|
39
39
|
# hear 'What time is it?' # Implicitly staying.
|
40
40
|
#
|
41
|
-
#
|
42
|
-
# hear 'What time is it?' =>
|
41
|
+
# Example for staying in the same state and doing something:
|
42
|
+
# hear 'What time is it?' => ->() { "I'm staying in the same state" }
|
43
43
|
#
|
44
44
|
def hear transitions
|
45
45
|
transitions = { transitions => name } unless transitions.respond_to?(:to_hash)
|
@@ -58,6 +58,12 @@ module James
|
|
58
58
|
@exit_block = block
|
59
59
|
end
|
60
60
|
|
61
|
+
#
|
62
|
+
#
|
63
|
+
def transition &block
|
64
|
+
|
65
|
+
end
|
66
|
+
|
61
67
|
# By default, a state is not chainable.
|
62
68
|
#
|
63
69
|
def chainable?
|
data/lib/james/visitor.rb
CHANGED
@@ -8,6 +8,9 @@ module James
|
|
8
8
|
# Note: A visitor should generally be very stupid.
|
9
9
|
# Note 2: We could call this Hearing, or Ear ;)
|
10
10
|
#
|
11
|
+
# TODO Add a timer which resets the state to the
|
12
|
+
# initial state.
|
13
|
+
#
|
11
14
|
class Visitor
|
12
15
|
|
13
16
|
attr_reader :initial, :timer
|
@@ -46,7 +49,7 @@ module James
|
|
46
49
|
def transition phrase
|
47
50
|
state_or_lambda = current.next_for phrase
|
48
51
|
if state_or_lambda.respond_to?(:call)
|
49
|
-
|
52
|
+
current.__transition__ &state_or_lambda # Don't transition.
|
50
53
|
else
|
51
54
|
self.current = state_or_lambda
|
52
55
|
end
|
@@ -36,22 +36,6 @@ describe 'TestDialogue' do
|
|
36
36
|
visitor.hear('stay') {}
|
37
37
|
visitor.current.name.should == :first
|
38
38
|
end
|
39
|
-
it 'calls the entrance/exits correctly' do
|
40
|
-
dialogue.should_receive(:respond_to?).once.with(:enter_second).and_return true
|
41
|
-
dialogue.should_receive(:enter_second).once
|
42
|
-
|
43
|
-
dialogue.should_receive(:respond_to?).once.with(:exit_second).and_return true
|
44
|
-
dialogue.should_receive(:exit_second).once
|
45
|
-
|
46
|
-
dialogue.should_receive(:respond_to?).once.with(:enter_first).and_return true
|
47
|
-
dialogue.should_receive(:enter_first).once
|
48
|
-
|
49
|
-
dialogue.should_receive(:respond_to?).once.with(:exit_first).and_return true
|
50
|
-
dialogue.should_receive(:exit_first).once
|
51
|
-
|
52
|
-
visitor.hear 'go'
|
53
|
-
visitor.hear 'back'
|
54
|
-
end
|
55
39
|
end
|
56
40
|
end
|
57
41
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
+
require File.expand_path '../../../../lib/james/state_api', __FILE__
|
3
4
|
require File.expand_path '../../../../lib/james/dialogue_api', __FILE__
|
4
5
|
require File.expand_path '../../../../lib/james/dialogue_internals', __FILE__
|
5
6
|
require File.expand_path '../../../../lib/james/builtin/core_dialogue', __FILE__
|
@@ -44,6 +45,29 @@ describe James::Dialogue do
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
describe 'hear with lambda' do
|
49
|
+
let(:dialogue) do
|
50
|
+
class Test
|
51
|
+
include James::Dialogue
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@bla = 'some bla'
|
55
|
+
end
|
56
|
+
|
57
|
+
state :test do
|
58
|
+
hear 'bla' => ->(){ @bla }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
Test.new
|
62
|
+
end
|
63
|
+
it "is instance eval'd" do
|
64
|
+
test_state = dialogue.state_for :test
|
65
|
+
test_state.hear 'bla' do |result|
|
66
|
+
result.should == 'some bla'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
47
71
|
describe 'initialization' do
|
48
72
|
it 'can be included' do
|
49
73
|
expect do
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: james
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.12
|
6
6
|
platform: universal-darwin-10
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
12
|
+
date: 2011-05-17 00:00:00 +10:00
|
13
13
|
default_executable: james
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|