apollo 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -3
- data/VERSION +1 -1
- data/apollo.gemspec +3 -2
- data/lib/apollo.rb +9 -7
- data/lib/apollo/active_record_extensions.rb +38 -0
- data/lib/apollo/specification.rb +10 -6
- data/lib/apollo/state.rb +2 -2
- data/lib/apollo/state_set.rb +7 -0
- metadata +4 -3
- data/lib/apollo/active_record_instance_methods.rb +0 -24
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
Apollo Changelog
|
2
2
|
================
|
3
3
|
|
4
|
-
1.
|
4
|
+
## 1.2
|
5
|
+
|
6
|
+
* Added `StateSet` class. (ace5f98)
|
7
|
+
* Renamed `State#sets` to `State#set_names`. (d3185f5)
|
8
|
+
* Added `ActiveRecordExtensions` for instance & class methods. (baf6177)
|
9
|
+
* Added AR class method `state_set_sql` for easy SQL usage.
|
10
|
+
|
11
|
+
## 1.1
|
5
12
|
|
6
13
|
* Added state sets. (7498cf0)
|
7
14
|
* Unbranded methods. E.g. `Apollo::apollo` -> `Apollo::state_machine` (f8b42b8)
|
8
15
|
|
9
|
-
1.0
|
10
|
-
|
16
|
+
## 1.0
|
17
|
+
|
11
18
|
This is an initial release of the Apollo fork from [Workflow](http://github.com/geekq/workflow). The reason I decided to fork Workflow, and in particular change the name, is because I feel that Workflow is an excellent starting point for my needs; however, my desire for Apollo is somewhat different from the desires of the creators of Workflow. **In no way is my fork (and renaming) intended to be any kind of insult or intellectual rights infringement.** I chose Workflow for the basis of Apollo because I feel it is the **best** state machine gem available. I will most certainly maintain the original MIT-LICENSE as apart of Apollo so long as *any* portion of the code is derived from Workflow (which I suspect will always be the case).
|
12
19
|
|
13
20
|
* Rebranded modules from "workflow" to "apollo".
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/apollo.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apollo}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Travis D. Warlick, Jr."]
|
@@ -25,10 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"apollo.gemspec",
|
27
27
|
"lib/apollo.rb",
|
28
|
-
"lib/apollo/
|
28
|
+
"lib/apollo/active_record_extensions.rb",
|
29
29
|
"lib/apollo/event.rb",
|
30
30
|
"lib/apollo/specification.rb",
|
31
31
|
"lib/apollo/state.rb",
|
32
|
+
"lib/apollo/state_set.rb",
|
32
33
|
"test/couchtiny_example.rb",
|
33
34
|
"test/main_test.rb",
|
34
35
|
"test/readme_example.rb",
|
data/lib/apollo.rb
CHANGED
@@ -16,10 +16,11 @@
|
|
16
16
|
# Copyright (c) 2008-2009 Vodafone
|
17
17
|
# Copyright (c) 2007-2008 Ryan Allen, FlashDen Pty Ltd
|
18
18
|
module Apollo
|
19
|
-
autoload :Event,
|
20
|
-
autoload :State,
|
21
|
-
autoload :
|
22
|
-
autoload :
|
19
|
+
autoload :Event, 'apollo/event'
|
20
|
+
autoload :State, 'apollo/state'
|
21
|
+
autoload :StateSet, 'apollo/state_set'
|
22
|
+
autoload :Specification, 'apollo/specification'
|
23
|
+
autoload :ActiveRecordExtensions, 'apollo/active_record_extensions'
|
23
24
|
|
24
25
|
# The current version
|
25
26
|
VERSION = File.read(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'VERSION')).strip
|
@@ -74,7 +75,7 @@ module Apollo
|
|
74
75
|
@apollo_spec.state_sets.keys.each do |set_name|
|
75
76
|
module_eval do
|
76
77
|
define_method "#{set_name}?" do
|
77
|
-
current_state.
|
78
|
+
current_state.set_names.include?(set_name.to_sym)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
@@ -219,8 +220,9 @@ module Apollo
|
|
219
220
|
klass.extend ClassMethods
|
220
221
|
if Object.const_defined?(:ActiveRecord)
|
221
222
|
if klass < ActiveRecord::Base
|
222
|
-
|
223
|
-
|
223
|
+
klass.send :include, ActiveRecordExtensions::InstanceMethods
|
224
|
+
klass.extend ActiveRecordExtensions::ClassMethods
|
225
|
+
klass.before_validation :write_initial_state
|
224
226
|
end
|
225
227
|
end
|
226
228
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Apollo
|
2
|
+
module ActiveRecordExtensions
|
3
|
+
module InstanceMethods
|
4
|
+
def load_current_state
|
5
|
+
read_attribute(self.class.current_state_column)
|
6
|
+
end
|
7
|
+
|
8
|
+
# On transition the new current state is immediately saved in the
|
9
|
+
# database.
|
10
|
+
def persist_current_state(new_value)
|
11
|
+
update_attribute self.class.current_state_column, new_value
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Motivation: even if NULL is stored in the current_state database column,
|
17
|
+
# the current_state is correctly recognized in the Ruby code. The problem
|
18
|
+
# arises when you want to SELECT records filtering by the value of initial
|
19
|
+
# state. That's why it is important to save the string with the name of the
|
20
|
+
# initial state in all the new records.
|
21
|
+
def write_initial_state
|
22
|
+
write_attribute self.class.current_state_column, current_state.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def state_set_sql( set_name, options = {} )
|
28
|
+
quotes = (options[:quotes] or %('))
|
29
|
+
join = (options[:join] or %(,))
|
30
|
+
surround = (options[:surround] or ['(',')'])
|
31
|
+
|
32
|
+
str = state_machine.state_sets[set_name.to_sym].state_names
|
33
|
+
str = str.collect { |state_name| quotes + state_name + quotes }.join(join)
|
34
|
+
surround.first + str + surround.last
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/apollo/specification.rb
CHANGED
@@ -22,19 +22,23 @@ module Apollo
|
|
22
22
|
instance_eval(&events_and_etc) if events_and_etc
|
23
23
|
end
|
24
24
|
|
25
|
-
def state_set(
|
26
|
-
validate_state_set_name(
|
25
|
+
def state_set(set_name, *state_names)
|
26
|
+
validate_state_set_name(set_name)
|
27
27
|
|
28
|
-
|
28
|
+
state_names.flatten!
|
29
|
+
state_names.collect! {|n| n.to_sym}
|
30
|
+
state_names.uniq!
|
31
|
+
|
32
|
+
set = StateSet.new
|
29
33
|
state_names.each do |state_name|
|
30
34
|
if state = @states[state_name]
|
31
35
|
set << state
|
32
|
-
state.
|
36
|
+
state.set_names << set_name.to_sym
|
33
37
|
else
|
34
|
-
raise ApolloDefinitionError, "Unknown state: #{
|
38
|
+
raise ApolloDefinitionError, "Unknown state: #{state_name}"
|
35
39
|
end
|
36
40
|
end
|
37
|
-
@state_sets[
|
41
|
+
@state_sets[set_name] = set
|
38
42
|
end
|
39
43
|
|
40
44
|
def event(name, args = {}, &action)
|
data/lib/apollo/state.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Apollo
|
2
2
|
class State
|
3
|
-
attr_accessor :name, :events, :meta, :on_entry, :on_exit, :
|
3
|
+
attr_accessor :name, :events, :meta, :on_entry, :on_exit, :set_names
|
4
4
|
|
5
5
|
def initialize(name, meta = {})
|
6
|
-
@name, @events, @meta, @
|
6
|
+
@name, @events, @meta, @set_names = name, Hash.new, meta, Set.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_s
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 1.
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis D. Warlick, Jr.
|
@@ -37,10 +37,11 @@ files:
|
|
37
37
|
- VERSION
|
38
38
|
- apollo.gemspec
|
39
39
|
- lib/apollo.rb
|
40
|
-
- lib/apollo/
|
40
|
+
- lib/apollo/active_record_extensions.rb
|
41
41
|
- lib/apollo/event.rb
|
42
42
|
- lib/apollo/specification.rb
|
43
43
|
- lib/apollo/state.rb
|
44
|
+
- lib/apollo/state_set.rb
|
44
45
|
- test/couchtiny_example.rb
|
45
46
|
- test/main_test.rb
|
46
47
|
- test/readme_example.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Apollo
|
2
|
-
module ActiveRecordInstanceMethods
|
3
|
-
def load_current_state
|
4
|
-
read_attribute(self.class.current_state_column)
|
5
|
-
end
|
6
|
-
|
7
|
-
# On transition the new current state is immediately saved in the
|
8
|
-
# database.
|
9
|
-
def persist_current_state(new_value)
|
10
|
-
update_attribute self.class.current_state_column, new_value
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# Motivation: even if NULL is stored in the current_state database column,
|
16
|
-
# the current_state is correctly recognized in the Ruby code. The problem
|
17
|
-
# arises when you want to SELECT records filtering by the value of initial
|
18
|
-
# state. That's why it is important to save the string with the name of the
|
19
|
-
# initial state in all the new records.
|
20
|
-
def write_initial_state
|
21
|
-
write_attribute self.class.current_state_column, current_state.to_s
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|