flow_machine 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/flow_machine.rb +0 -1
- data/lib/flow_machine/version.rb +1 -1
- metadata +1 -4
- data/lib/flow_machine/factory.rb +0 -24
- data/spec/flow_machine/deprecated_factory_methods_spec.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ddc0a3879f962108fb9bc5616667131e0e3830e
|
4
|
+
data.tar.gz: 1ce4561e9efd33531e4d3754b24ef653b3c047bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569a2f85b79f0328cf6af65d4a2f5e11a783b7c06c88380f6ef7f6a6e7e551a2b96d541d0ead6681b5f27eeaf99f0cfd6ed50327d843895750dc6e5ee199aea0
|
7
|
+
data.tar.gz: 12b15553a5ec36b9e49d1fc8f801c4ccf554a0d809b75ddcafbc0cea4b64043b35f8d6a1148f423546b34fbf52d4057c33fde101296262f535b15140c47d04b3
|
data/README.md
CHANGED
@@ -8,6 +8,10 @@ The basic features will work with any PORO, and more features and callbacks are
|
|
8
8
|
|
9
9
|
After exploring several of the existing Ruby state machine options, they all seem too tightly coupled to an ORM models and tend to pollute the object model's code far too much. The goal of this gem is to provide a clean, testable interface for working with a state machine that decouples as much as possible from the model object itself.
|
10
10
|
|
11
|
+
## Upgrading
|
12
|
+
|
13
|
+
See [UPGRADE.md](UPGRADE.md) for details
|
14
|
+
|
11
15
|
## Simple Usage
|
12
16
|
|
13
17
|
```ruby
|
@@ -132,6 +136,28 @@ Declared as an option to the `transition` method inside an `event` block.
|
|
132
136
|
|
133
137
|
`transition to: :published, after: :send_mailing_list_email`
|
134
138
|
|
139
|
+
## FlowMachine::Workflow.for
|
140
|
+
|
141
|
+
You can easily access the workflow for your particular object, class, or collection of objects.
|
142
|
+
|
143
|
+
Examples:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
blog = BlogPost.new
|
147
|
+
FlowMachine::Workflow.for(blog) # => BlogPostWorkflow
|
148
|
+
|
149
|
+
FlowMachine::Workflow.for(BlogPost) # => BlogPostWorkflow
|
150
|
+
```
|
151
|
+
|
152
|
+
You can also create an collection of workflow objects via:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
blog_posts = BlogPost.all
|
156
|
+
|
157
|
+
FlowMachine::Workflow.collection_for(blog_posts) # => [BlogPostWorkfow.new(blog_post[0]), ..., BlogPostWorkflow.new(blog_post[n])
|
158
|
+
```
|
159
|
+
|
160
|
+
|
135
161
|
## Scopes and Predicate methods
|
136
162
|
|
137
163
|
If you want scopes and predicate methods defined on your model, use the following:
|
data/lib/flow_machine.rb
CHANGED
data/lib/flow_machine/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Hanggi
|
@@ -65,14 +65,12 @@ files:
|
|
65
65
|
- lib/flow_machine.rb
|
66
66
|
- lib/flow_machine/callback.rb
|
67
67
|
- lib/flow_machine/change_callback.rb
|
68
|
-
- lib/flow_machine/factory.rb
|
69
68
|
- lib/flow_machine/state_callback.rb
|
70
69
|
- lib/flow_machine/version.rb
|
71
70
|
- lib/flow_machine/workflow.rb
|
72
71
|
- lib/flow_machine/workflow/factory_methods.rb
|
73
72
|
- lib/flow_machine/workflow_state.rb
|
74
73
|
- lib/tasks/workflow_tasks.rake
|
75
|
-
- spec/flow_machine/deprecated_factory_methods_spec.rb
|
76
74
|
- spec/flow_machine/factory_methods_spec.rb
|
77
75
|
- spec/flow_machine/multiple_workflow_spec.rb
|
78
76
|
- spec/flow_machine/workflow_callback_spec.rb
|
@@ -105,7 +103,6 @@ signing_key:
|
|
105
103
|
specification_version: 4
|
106
104
|
summary: A class-based state machine.
|
107
105
|
test_files:
|
108
|
-
- spec/flow_machine/deprecated_factory_methods_spec.rb
|
109
106
|
- spec/flow_machine/factory_methods_spec.rb
|
110
107
|
- spec/flow_machine/multiple_workflow_spec.rb
|
111
108
|
- spec/flow_machine/workflow_callback_spec.rb
|
data/lib/flow_machine/factory.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module FlowMachine
|
2
|
-
# Deprecated in favor of calling these methods directly off of FlowMachine
|
3
|
-
# which are defined in FlowMachine::FactoryMethods
|
4
|
-
module Factory
|
5
|
-
def self.workflow_for(object, options = {})
|
6
|
-
deprecate :workflow_for, :for
|
7
|
-
FlowMachine::Workflow.for(object, options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.workflow_for_collection(collection, options = {})
|
11
|
-
deprecate :workflow_for_collection, :for_collection
|
12
|
-
FlowMachine::Workflow.for_collection(collection, options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.workflow_class_for(object_or_class)
|
16
|
-
deprecate :workflow_class_for, :class_for
|
17
|
-
FlowMachine::Workflow.class_for(object_or_class)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.deprecate(old_method_name, new_method_name)
|
21
|
-
warn "FlowMachine::Factory.#{old_method_name} is deprecated. Use FlowMachine::Workflow.#{new_method_name} instead."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
RSpec.describe FlowMachine::Factory do
|
2
|
-
class TestClass; end
|
3
|
-
|
4
|
-
class TestClassWorkflow
|
5
|
-
include FlowMachine::Workflow
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '.workflow_class_for' do
|
9
|
-
subject(:workflow_class) { described_class.workflow_class_for(target) }
|
10
|
-
before { expect(described_class).to receive(:deprecate) }
|
11
|
-
|
12
|
-
describe 'with a class' do
|
13
|
-
let(:target) { TestClass }
|
14
|
-
it { should eq(TestClassWorkflow) }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'with an object' do
|
18
|
-
let(:target) { TestClass.new }
|
19
|
-
it { should eq(TestClassWorkflow) }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '.workflow_for' do
|
24
|
-
subject(:workflow) { described_class.workflow_for(target) }
|
25
|
-
before { expect(described_class).to receive(:deprecate) }
|
26
|
-
|
27
|
-
class SomeNewClass; end
|
28
|
-
|
29
|
-
describe 'not found' do
|
30
|
-
let(:target) { SomeNewClass.new }
|
31
|
-
it { should be_nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'with an object' do
|
35
|
-
let(:target) { TestClass.new }
|
36
|
-
it { should be_an_instance_of(TestClassWorkflow) }
|
37
|
-
its(:object) { should eq(target) }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'with an array of objects' do
|
41
|
-
let(:target) { [TestClass.new, TestClass.new] }
|
42
|
-
it { should match [an_instance_of(TestClassWorkflow), an_instance_of(TestClassWorkflow)] }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '.workflow_for_collection' do
|
47
|
-
subject(:result) { described_class.workflow_for_collection(target) }
|
48
|
-
before { expect(described_class).to receive(:deprecate) }
|
49
|
-
|
50
|
-
let(:target) { [TestClass.new, TestClass.new] }
|
51
|
-
it { should match [an_instance_of(TestClassWorkflow), an_instance_of(TestClassWorkflow)] }
|
52
|
-
end
|
53
|
-
end
|