flojo 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -1
- data/Rakefile +1 -1
- data/flojo.gemspec +9 -9
- data/lib/flojo.rb +16 -9
- data/test/test_active_record.rb +4 -4
- data/test/test_db.sqlite3 +0 -0
- metadata +31 -43
data/CHANGELOG
CHANGED
@@ -1,2 +1,3 @@
|
|
1
1
|
0.5.1 Added workflow_states and transition parameter checks.
|
2
|
-
0.5.1.1 Renamed valid_state method to valid_states?
|
2
|
+
0.5.1.1 Renamed valid_state method to valid_states?
|
3
|
+
0.5.3 Fixed state persistence. State is persisted even if you don't use the! versions of event methods. New Active record object now have the default state even before save. Updated the tests.
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('flojo', '0.5.
|
5
|
+
Echoe.new('flojo', '0.5.3') do |p|
|
6
6
|
p.description = "ActiveRecord aware workflow (state machine) module that will also work with any plain old ruby object."
|
7
7
|
p.summary = "When used within an ActiveRecord subclass, flojo events can automatically save a record after a transition.
|
8
8
|
|
data/flojo.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.5.
|
4
|
+
s.name = "flojo"
|
5
|
+
s.version = "0.5.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Joey Adarkwah"]
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
9
|
+
s.date = "2012-01-19"
|
10
|
+
s.description = "ActiveRecord aware workflow (state machine) module that will also work with any plain old ruby object."
|
11
|
+
s.email = "alternegro @nospam@ me.com"
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/flojo.rb"]
|
13
13
|
s.files = ["CHANGELOG", "MIT_LICENSE", "README.rdoc", "Rakefile", "lib/flojo.rb", "test/test_active_record.rb", "test/test_db.sqlite3", "test/test_helper.rb", "test/test_poro.rb", "Manifest", "flojo.gemspec"]
|
14
|
-
s.homepage =
|
14
|
+
s.homepage = "http://github.com/alternegro/flojo"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Flojo", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
17
|
+
s.rubyforge_project = "flojo"
|
18
|
+
s.rubygems_version = "1.8.15"
|
19
|
+
s.summary = "When used within an ActiveRecord subclass, flojo events can automatically save a record after a transition. After including the module in your class and configuring it with an event _event_, and a state _state_, you can interact with instances of that class using the dynamically generated methods of the following form: +object.wf_event+ - Triggers event and invokes any applicable transitions +object.wf_event!+ - Behaves just like +object.wf_event+ but will also persist object. +object.wf_state?+ - Returns true if the current workflow state is _state_. +object.wf_current_state+ - Returns the objects current state."
|
20
20
|
s.test_files = ["test/test_active_record.rb", "test/test_helper.rb", "test/test_poro.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
data/lib/flojo.rb
CHANGED
@@ -5,11 +5,19 @@ module Flojo
|
|
5
5
|
attr_writer :wf_current_state
|
6
6
|
attr_accessor :_wf_current_event_transition_map, :wf_previous_state
|
7
7
|
protected :wf_current_state=, :_set_workflow_state
|
8
|
-
|
8
|
+
|
9
9
|
def wf_current_state
|
10
10
|
wf_current_state = @wf_current_state.nil? ? wf_initial_state : @wf_current_state
|
11
11
|
end
|
12
12
|
|
13
|
+
if respond_to?(:after_initialize)
|
14
|
+
after_initialize :flojo_active_record_init
|
15
|
+
|
16
|
+
def flojo_active_record_init
|
17
|
+
self.wf_state = self.wf_current_state.to_s if self.respond_to?(:wf_state=)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
def wf_initial_state
|
14
22
|
st = self.respond_to?(:wf_state) ? (wf_state || self.class.wf_states[0]) : self.class.wf_states[0]
|
15
23
|
st.to_sym
|
@@ -22,7 +30,7 @@ module Flojo
|
|
22
30
|
raise "Invalid Parameter. State array elements should be symbols" unless Symbol === st
|
23
31
|
end
|
24
32
|
|
25
|
-
|
33
|
+
self.synthesize_state_query_methods
|
26
34
|
end
|
27
35
|
|
28
36
|
def self.wf_states
|
@@ -30,14 +38,13 @@ module Flojo
|
|
30
38
|
end
|
31
39
|
|
32
40
|
def self.synthesize_state_query_methods
|
33
|
-
|
34
|
-
|
41
|
+
@workflow_states.each {|st| define_method("wf_#{st}?") { st.eql?(wf_current_state)}}
|
42
|
+
end
|
35
43
|
|
36
|
-
|
37
|
-
|
44
|
+
def self.valid_states?(*states)
|
45
|
+
states.each {|st| return false if (!@workflow_states.include?(st) && (st != :any)) || !(Symbol === st)}
|
38
46
|
return true
|
39
|
-
end
|
40
|
-
|
47
|
+
end
|
41
48
|
end
|
42
49
|
|
43
50
|
host.class_eval("def self.transition(start_state, end_state); raise 'Invalid Transition State' unless self.valid_states?(start_state, end_state); @wf_current_event_transition_map[start_state]=end_state; end")
|
@@ -76,6 +83,7 @@ module Flojo
|
|
76
83
|
|
77
84
|
if (state != self.wf_current_state) && (!state.nil?)
|
78
85
|
self.wf_current_state=state
|
86
|
+
self.wf_state = self.wf_current_state if self.respond_to?(:wf_state=)
|
79
87
|
|
80
88
|
eval("wf_on_#{event}") if event && (self.class.method_defined? "wf_on_#{event}")
|
81
89
|
eval("wf_on_exit_#{wf_current_state}") if self.class.method_defined? "wf_on_exit_#{wf_current_state}"
|
@@ -86,7 +94,6 @@ module Flojo
|
|
86
94
|
end
|
87
95
|
|
88
96
|
def _wf_after_transition_save!
|
89
|
-
self.wf_state = self.wf_current_state if self.respond_to?(:wf_state=)
|
90
97
|
save! if self.respond_to?(:save!)
|
91
98
|
end
|
92
99
|
|
data/test/test_active_record.rb
CHANGED
@@ -28,8 +28,8 @@ class Counter < ActiveRecord::Base
|
|
28
28
|
|
29
29
|
event :down do
|
30
30
|
transition :one, :three
|
31
|
-
|
32
|
-
|
31
|
+
transition :two, :one
|
32
|
+
transition :three, :two
|
33
33
|
end
|
34
34
|
|
35
35
|
def wf_on_enter_one
|
@@ -55,7 +55,6 @@ class Counter < ActiveRecord::Base
|
|
55
55
|
def wf_after_save
|
56
56
|
"wf_after_save"
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
59
|
|
61
60
|
|
@@ -76,6 +75,7 @@ class TestWorkflow < Test::Unit::TestCase
|
|
76
75
|
def test_stored_counter
|
77
76
|
stored_counter = Counter.first
|
78
77
|
assert_equal(:one, stored_counter.wf_current_state, "Initial state must be :one")
|
78
|
+
assert_equal("one", stored_counter.wf_state, "Stored state must be one")
|
79
79
|
|
80
80
|
stored_counter.wf_up!
|
81
81
|
assert_equal(:two, stored_counter.wf_current_state, "Current state must be :two")
|
@@ -95,7 +95,7 @@ class TestWorkflow < Test::Unit::TestCase
|
|
95
95
|
|
96
96
|
def test_new_counter
|
97
97
|
new_counter = Counter.new
|
98
|
-
assert_equal(
|
98
|
+
assert_equal("one", new_counter.wf_state, "Stored state must be nil")
|
99
99
|
assert_equal(:one, new_counter.wf_current_state, "Initial state must be :one")
|
100
100
|
assert_equal(1, Counter.count)
|
101
101
|
|
data/test/test_db.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,35 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: flojo
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 2
|
10
|
-
version: 0.5.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Joey Adarkwah
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-02-03 00:00:00 -05:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-01-19 00:00:00.000000000Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: ActiveRecord aware workflow (state machine) module that will also work
|
15
|
+
with any plain old ruby object.
|
23
16
|
email: alternegro @nospam@ me.com
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
29
20
|
- CHANGELOG
|
30
21
|
- README.rdoc
|
31
22
|
- lib/flojo.rb
|
32
|
-
files:
|
23
|
+
files:
|
33
24
|
- CHANGELOG
|
34
25
|
- MIT_LICENSE
|
35
26
|
- README.rdoc
|
@@ -41,47 +32,44 @@ files:
|
|
41
32
|
- test/test_poro.rb
|
42
33
|
- Manifest
|
43
34
|
- flojo.gemspec
|
44
|
-
has_rdoc: true
|
45
35
|
homepage: http://github.com/alternegro/flojo
|
46
36
|
licenses: []
|
47
|
-
|
48
37
|
post_install_message:
|
49
|
-
rdoc_options:
|
38
|
+
rdoc_options:
|
50
39
|
- --line-numbers
|
51
40
|
- --inline-source
|
52
41
|
- --title
|
53
42
|
- Flojo
|
54
43
|
- --main
|
55
44
|
- README.rdoc
|
56
|
-
require_paths:
|
45
|
+
require_paths:
|
57
46
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
48
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
54
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 1
|
75
|
-
- 2
|
76
|
-
version: "1.2"
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '1.2'
|
77
59
|
requirements: []
|
78
|
-
|
79
60
|
rubyforge_project: flojo
|
80
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.8.15
|
81
62
|
signing_key:
|
82
63
|
specification_version: 3
|
83
|
-
summary:
|
84
|
-
|
64
|
+
summary: ! 'When used within an ActiveRecord subclass, flojo events can automatically
|
65
|
+
save a record after a transition. After including the module in your class
|
66
|
+
and configuring it with an event _event_, and a state _state_, you can interact
|
67
|
+
with instances of that class using the dynamically generated methods of the following
|
68
|
+
form: +object.wf_event+ - Triggers event and invokes any applicable transitions
|
69
|
+
+object.wf_event!+ - Behaves just like +object.wf_event+ but will also persist object.
|
70
|
+
+object.wf_state?+ - Returns true if the current workflow state is _state_. +object.wf_current_state+
|
71
|
+
- Returns the objects current state.'
|
72
|
+
test_files:
|
85
73
|
- test/test_active_record.rb
|
86
74
|
- test/test_helper.rb
|
87
75
|
- test/test_poro.rb
|