james 0.0.11-universal-darwin-10 → 0.0.12-universal-darwin-10

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.
@@ -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
- # Note: We could expand on this with
42
- # hear 'What time is it?' => lambda { Do something here with the time, returns to same state }
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?
@@ -29,6 +29,9 @@ module James
29
29
  def __exit__
30
30
  @exit_block && context.instance_eval(&@exit_block)
31
31
  end
32
+ def __transition__ &block
33
+ context.instance_eval &block
34
+ end
32
35
 
33
36
  end
34
37
 
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
- state_or_lambda.call # Don't transition.
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.11
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-15 00:00:00 +10:00
12
+ date: 2011-05-17 00:00:00 +10:00
13
13
  default_executable: james
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency