stately 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/stately.rb +8 -4
- data/lib/stately/version.rb +1 -1
- data/spec/functional/two_objets_spec.rb +33 -0
- data/spec/unit/stately_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a53df7047916b347c3064c06dffd6a23c683efa
|
4
|
+
data.tar.gz: 5f49e5f0ee667963bb48c9910fdb3da756b5b9a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b6cbf227d0c8db10d54d5478ec6de0d648b33c4107a789ee225dc3de4081034b66c91baf8fa7212419965a00c051675e25b64abd66c83830283ba29f0c71305
|
7
|
+
data.tar.gz: e9efc6b438cda558b33657235fcb80b986671ae5c6687172e192c29998b9ab40d2d13a270c8494404788320b69f90370a8db525a4b58873584e0f9f3f92ff40d
|
data/Gemfile.lock
CHANGED
data/lib/stately.rb
CHANGED
@@ -53,20 +53,20 @@ module Stately
|
|
53
53
|
options = opts.last.is_a?(Hash) ? opts.last : {}
|
54
54
|
options[:attr] ||= :state
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
@stately_machine = Stately::Machine.new(options[:attr], options[:start])
|
57
|
+
@stately_machine.instance_eval(&block) if block_given?
|
58
58
|
|
59
59
|
include Stately::InstanceMethods
|
60
60
|
end
|
61
61
|
|
62
62
|
# Get the current Stately::Machine object
|
63
63
|
def stately_machine
|
64
|
-
|
64
|
+
self.instance_variable_get(:@stately_machine)
|
65
65
|
end
|
66
66
|
|
67
67
|
# Set the current Stately::Machine object
|
68
68
|
def stately_machine=(obj)
|
69
|
-
|
69
|
+
@stately_machine = obj
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -108,6 +108,10 @@ module Stately
|
|
108
108
|
|
109
109
|
private
|
110
110
|
|
111
|
+
def stately_machine
|
112
|
+
self.class.stately_machine
|
113
|
+
end
|
114
|
+
|
111
115
|
def allowed_state_transition?(to_state)
|
112
116
|
if current_state == to_state.to_s
|
113
117
|
raise InvalidTransition,
|
data/lib/stately/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "two objects" do
|
5
|
+
class1 = Class.new(OpenStruct) do
|
6
|
+
stately :start => :object1_started, :attr => :object1_state do
|
7
|
+
state :object1_processed, :action => :processed do
|
8
|
+
allow_from :object1_started
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class2 = Class.new(OpenStruct) do
|
14
|
+
stately :start => :object2_started, :attr => :object2_state do
|
15
|
+
state :object2_processed, :action => :processed do
|
16
|
+
allow_from :object2_started
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "should have individual state" do
|
22
|
+
let!(:object1) { class1.new }
|
23
|
+
let!(:object2) { class2.new }
|
24
|
+
|
25
|
+
it "object1 should get the value of object1_state" do
|
26
|
+
object1.respond_to?(:object1_state).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "object2 should get the value of object2_state" do
|
30
|
+
object2.respond_to?(:object2_state).should be_true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/unit/stately_spec.rb
CHANGED
@@ -16,8 +16,8 @@ describe Stately::InstanceMethods do
|
|
16
16
|
|
17
17
|
describe 'initialize' do
|
18
18
|
it 'creates a new Stately::Machine' do
|
19
|
-
@object.stately_machine.class.should == Stately::Machine
|
20
|
-
@object.stately_machine.should == @test_class.stately_machine
|
19
|
+
@object.class.stately_machine.class.should == Stately::Machine
|
20
|
+
@object.class.stately_machine.should == @test_class.stately_machine
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'sets initial state' do
|
@@ -49,11 +49,11 @@ describe Stately::InstanceMethods do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'defines an instance-level accessor called stately_machine' do
|
52
|
-
@test_class.method_defined?(:stately_machine).should be_true
|
52
|
+
@test_class.class.method_defined?(:stately_machine).should be_true
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'defines a class-level setter called stately_machine=' do
|
56
|
-
@test_class.respond_to?(:stately_machine=).should be_true
|
56
|
+
@test_class.class.respond_to?(:stately_machine=).should be_true
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'defines an instance-level setter called stately_machine=' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stately
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Twomey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/stately/version.rb
|
104
104
|
- lib/tasks/stately_tasks.rake
|
105
105
|
- spec/functional/stately_spec.rb
|
106
|
+
- spec/functional/two_objets_spec.rb
|
106
107
|
- spec/spec_helper.rb
|
107
108
|
- spec/unit/stately/machine_spec.rb
|
108
109
|
- spec/unit/stately/state_spec.rb
|