flow_machine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/flow_machine.rb +1 -0
- data/lib/flow_machine/factory.rb +13 -16
- data/lib/flow_machine/version.rb +1 -1
- data/lib/flow_machine/workflow.rb +3 -0
- data/lib/flow_machine/workflow/factory_methods.rb +28 -0
- data/spec/flow_machine/{factory_spec.rb → deprecated_factory_methods_spec.rb} +5 -0
- data/spec/flow_machine/factory_methods_spec.rb +48 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c615b72e507282a2a54032525a6874fbb8961ee
|
4
|
+
data.tar.gz: 461ed246d3ae29d77e3818630b73c9483e4959c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d5690d15116ee1c6b853289f484a1f9aef09669b13d06460b82ec5b50e0bcdf318d9acff85579fb583ebfded8e0d7cf2a3a640076f5a1b5a8d8b7a78a5b6d4a
|
7
|
+
data.tar.gz: 8683235ed2e91f8874941f5be89c0e4f9e53f7a4d4329e9a21d653a904210b65db28265b4b2efd9ebbb308f84543c842c3789ae2cb390a84080659e8a1d28588
|
data/README.md
CHANGED
data/lib/flow_machine.rb
CHANGED
data/lib/flow_machine/factory.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
module FlowMachine
|
2
|
-
|
2
|
+
# Deprecated in favor of calling these methods directly off of FlowMachine
|
3
|
+
# which are defined in FlowMachine::FactoryMethods
|
4
|
+
module Factory
|
3
5
|
def self.workflow_for(object, options = {})
|
4
|
-
|
5
|
-
|
6
|
-
return workflow_for_collection(object, options) if object.respond_to?(:map)
|
7
|
-
|
8
|
-
klazz = workflow_class_for(object)
|
9
|
-
return nil unless klazz
|
10
|
-
klazz.new(object, options)
|
6
|
+
deprecate :workflow_for, :for
|
7
|
+
FlowMachine::Workflow.for(object, options)
|
11
8
|
end
|
12
9
|
|
13
10
|
def self.workflow_for_collection(collection, options = {})
|
14
|
-
|
11
|
+
deprecate :workflow_for_collection, :for_collection
|
12
|
+
FlowMachine::Workflow.for_collection(collection, options)
|
15
13
|
end
|
16
14
|
|
17
15
|
def self.workflow_class_for(object_or_class)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
nil
|
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."
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
data/lib/flow_machine/version.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "active_support/core_ext/module/delegation"
|
2
2
|
require "active_support/core_ext/object/try"
|
3
|
+
require "flow_machine/workflow/factory_methods"
|
3
4
|
|
4
5
|
module FlowMachine
|
5
6
|
module Workflow
|
7
|
+
extend FlowMachine::FactoryMethods
|
8
|
+
|
6
9
|
def self.included(base)
|
7
10
|
base.extend(ClassMethods)
|
8
11
|
base.send(:attr_reader, :object)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# These methods are extended in the base FlowMachine module
|
2
|
+
module FlowMachine
|
3
|
+
module FactoryMethods
|
4
|
+
def for(object, options = {})
|
5
|
+
# If the object is enumerable, delegate. This allows workflow_for
|
6
|
+
# as shorthand
|
7
|
+
return for_collection(object, options) if object.respond_to?(:map)
|
8
|
+
|
9
|
+
klazz = class_for(object)
|
10
|
+
return nil unless klazz
|
11
|
+
klazz.new(object, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def for_collection(collection, options = {})
|
15
|
+
collection.map { |item| self.for(item, options) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def class_for(object_or_class)
|
19
|
+
if object_or_class.is_a? Class
|
20
|
+
"#{object_or_class.name}Workflow".constantize
|
21
|
+
else
|
22
|
+
self.class_for(object_or_class.class)
|
23
|
+
end
|
24
|
+
rescue NameError # if the workflow class doesn't exist
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -7,6 +7,7 @@ RSpec.describe FlowMachine::Factory do
|
|
7
7
|
|
8
8
|
describe '.workflow_class_for' do
|
9
9
|
subject(:workflow_class) { described_class.workflow_class_for(target) }
|
10
|
+
before { expect(described_class).to receive(:deprecate) }
|
10
11
|
|
11
12
|
describe 'with a class' do
|
12
13
|
let(:target) { TestClass }
|
@@ -21,6 +22,8 @@ RSpec.describe FlowMachine::Factory do
|
|
21
22
|
|
22
23
|
describe '.workflow_for' do
|
23
24
|
subject(:workflow) { described_class.workflow_for(target) }
|
25
|
+
before { expect(described_class).to receive(:deprecate) }
|
26
|
+
|
24
27
|
class SomeNewClass; end
|
25
28
|
|
26
29
|
describe 'not found' do
|
@@ -42,6 +45,8 @@ RSpec.describe FlowMachine::Factory do
|
|
42
45
|
|
43
46
|
describe '.workflow_for_collection' do
|
44
47
|
subject(:result) { described_class.workflow_for_collection(target) }
|
48
|
+
before { expect(described_class).to receive(:deprecate) }
|
49
|
+
|
45
50
|
let(:target) { [TestClass.new, TestClass.new] }
|
46
51
|
it { should match [an_instance_of(TestClassWorkflow), an_instance_of(TestClassWorkflow)] }
|
47
52
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
RSpec.describe FlowMachine::Workflow do
|
2
|
+
class TestClass; end
|
3
|
+
|
4
|
+
class TestClassWorkflow
|
5
|
+
include FlowMachine::Workflow
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.class_for' do
|
9
|
+
subject(:workflow_class) { described_class.class_for(target) }
|
10
|
+
|
11
|
+
describe 'with a class' do
|
12
|
+
let(:target) { TestClass }
|
13
|
+
it { should eq(TestClassWorkflow) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'with an object' do
|
17
|
+
let(:target) { TestClass.new }
|
18
|
+
it { should eq(TestClassWorkflow) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.for' do
|
23
|
+
subject(:workflow) { described_class.for(target) }
|
24
|
+
class SomeNewClass; end
|
25
|
+
|
26
|
+
describe 'not found' do
|
27
|
+
let(:target) { SomeNewClass.new }
|
28
|
+
it { should be_nil }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'with an object' do
|
32
|
+
let(:target) { TestClass.new }
|
33
|
+
it { should be_an_instance_of(TestClassWorkflow) }
|
34
|
+
its(:object) { should eq(target) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'with an array of objects' do
|
38
|
+
let(:target) { [TestClass.new, TestClass.new] }
|
39
|
+
it { should match [an_instance_of(TestClassWorkflow), an_instance_of(TestClassWorkflow)] }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.workflow_for_collection' do
|
44
|
+
subject(:result) { described_class.for_collection(target) }
|
45
|
+
let(:target) { [TestClass.new, TestClass.new] }
|
46
|
+
it { should match [an_instance_of(TestClassWorkflow), an_instance_of(TestClassWorkflow)] }
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Hanggi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -69,9 +69,11 @@ files:
|
|
69
69
|
- lib/flow_machine/state_callback.rb
|
70
70
|
- lib/flow_machine/version.rb
|
71
71
|
- lib/flow_machine/workflow.rb
|
72
|
+
- lib/flow_machine/workflow/factory_methods.rb
|
72
73
|
- lib/flow_machine/workflow_state.rb
|
73
74
|
- lib/tasks/workflow_tasks.rake
|
74
|
-
- spec/flow_machine/
|
75
|
+
- spec/flow_machine/deprecated_factory_methods_spec.rb
|
76
|
+
- spec/flow_machine/factory_methods_spec.rb
|
75
77
|
- spec/flow_machine/multiple_workflow_spec.rb
|
76
78
|
- spec/flow_machine/workflow_callback_spec.rb
|
77
79
|
- spec/flow_machine/workflow_change_callback_spec.rb
|
@@ -103,7 +105,8 @@ signing_key:
|
|
103
105
|
specification_version: 4
|
104
106
|
summary: A class-based state machine.
|
105
107
|
test_files:
|
106
|
-
- spec/flow_machine/
|
108
|
+
- spec/flow_machine/deprecated_factory_methods_spec.rb
|
109
|
+
- spec/flow_machine/factory_methods_spec.rb
|
107
110
|
- spec/flow_machine/multiple_workflow_spec.rb
|
108
111
|
- spec/flow_machine/workflow_callback_spec.rb
|
109
112
|
- spec/flow_machine/workflow_change_callback_spec.rb
|