apollo 1.2.0 → 1.3.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apollo.gemspec +8 -8
- data/lib/apollo/active_record_extensions.rb +42 -4
- metadata +19 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0.beta.1
|
data/apollo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apollo}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0.beta.1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Travis D. Warlick, Jr."]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-25}
|
13
13
|
s.email = %q{warlickt@operissystems.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -39,21 +39,21 @@ Gem::Specification.new do |s|
|
|
39
39
|
s.homepage = %q{http://github.com/tekwiz/apollo}
|
40
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
41
41
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.3.
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
43
|
s.summary = %q{A fork of workflow: a finite-state-machine-inspired API for modeling and interacting with what we tend to refer to as 'workflow'.}
|
44
44
|
s.test_files = [
|
45
|
-
"test/
|
45
|
+
"test/without_active_record_test.rb",
|
46
|
+
"test/couchtiny_example.rb",
|
46
47
|
"test/main_test.rb",
|
47
|
-
"test/readme_example.rb",
|
48
48
|
"test/test_helper.rb",
|
49
|
-
"test/
|
49
|
+
"test/readme_example.rb"
|
50
50
|
]
|
51
51
|
|
52
52
|
if s.respond_to? :specification_version then
|
53
53
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
54
|
s.specification_version = 3
|
55
55
|
|
56
|
-
if Gem::Version.new(Gem::
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
57
|
else
|
58
58
|
end
|
59
59
|
else
|
@@ -2,13 +2,22 @@ module Apollo
|
|
2
2
|
module ActiveRecordExtensions
|
3
3
|
module InstanceMethods
|
4
4
|
def load_current_state
|
5
|
-
|
5
|
+
if self.class.persist_string_state_name?
|
6
|
+
read_attribute(self.class.current_state_column)
|
7
|
+
else
|
8
|
+
self.class.state_id_to_name(read_attribute(self.class.current_state_id_column))
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
# On transition the new current state is immediately saved in the
|
9
13
|
# database.
|
10
14
|
def persist_current_state(new_value)
|
11
|
-
|
15
|
+
if self.class.persist_string_state_name?
|
16
|
+
update_attribute self.class.current_state_column, new_value
|
17
|
+
else
|
18
|
+
update_attribute self.class.current_state_id_column,
|
19
|
+
self.class.state_name_to_id(new_value)
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
private
|
@@ -19,7 +28,12 @@ module Apollo
|
|
19
28
|
# state. That's why it is important to save the string with the name of the
|
20
29
|
# initial state in all the new records.
|
21
30
|
def write_initial_state
|
22
|
-
|
31
|
+
if self.class.persist_string_state_name?
|
32
|
+
write_attribute self.class.current_state_column, current_state.to_s
|
33
|
+
else
|
34
|
+
write_attribute self.class.current_state_id_column,
|
35
|
+
self.class.state_name_to_id(current_state.to_s)
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
25
39
|
|
@@ -30,9 +44,33 @@ module Apollo
|
|
30
44
|
surround = (options[:surround] or ['(',')'])
|
31
45
|
|
32
46
|
str = state_machine.state_sets[set_name.to_sym].state_names
|
33
|
-
|
47
|
+
if persiste_string_state_name?
|
48
|
+
str = str.collect { |state_name| quotes + state_name + quotes }.join(join)
|
49
|
+
else
|
50
|
+
str = str.collect { |state_name| state_name_to_id(state_name) }.join(join)
|
51
|
+
end
|
34
52
|
surround.first + str + surround.last
|
35
53
|
end
|
54
|
+
|
55
|
+
def persist_string_state_name?
|
56
|
+
self.column_names.include?(self.current_state_column)
|
57
|
+
end
|
58
|
+
|
59
|
+
def state_id_to_name(state_id)
|
60
|
+
result = ActiveRecord::Base.connection.query "SELECT name FROM states WHERE klass = '#{self.to_s}' AND id = #{state_id}"
|
61
|
+
raise "Cannot find state." if result.empty?
|
62
|
+
result[0][0]
|
63
|
+
end
|
64
|
+
|
65
|
+
def state_name_to_id(state_name)
|
66
|
+
result = ActiveRecord::Base.connection.query "SELECT id FROM states WHERE klass = '#{self.to_s}' AND name = '#{state_name}'"
|
67
|
+
raise "Cannot find state" if result.empty?
|
68
|
+
result[0][0]
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_state_id_column
|
72
|
+
self.current_state_column.to_s+"_id"
|
73
|
+
end
|
36
74
|
end
|
37
75
|
end
|
38
76
|
end
|
metadata
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apollo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 62196401
|
5
|
+
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
+
- 3
|
8
9
|
- 0
|
9
|
-
|
10
|
+
- beta
|
11
|
+
- 1
|
12
|
+
version: 1.3.0.beta.1
|
10
13
|
platform: ruby
|
11
14
|
authors:
|
12
15
|
- Travis D. Warlick, Jr.
|
@@ -14,7 +17,7 @@ autorequire:
|
|
14
17
|
bindir: bin
|
15
18
|
cert_chain: []
|
16
19
|
|
17
|
-
date: 2010-
|
20
|
+
date: 2010-05-25 00:00:00 -05:00
|
18
21
|
default_executable:
|
19
22
|
dependencies: []
|
20
23
|
|
@@ -57,29 +60,35 @@ rdoc_options:
|
|
57
60
|
require_paths:
|
58
61
|
- lib
|
59
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
60
64
|
requirements:
|
61
65
|
- - ">="
|
62
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
63
68
|
segments:
|
64
69
|
- 0
|
65
70
|
version: "0"
|
66
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
67
73
|
requirements:
|
68
|
-
- - "
|
74
|
+
- - ">"
|
69
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 25
|
70
77
|
segments:
|
71
|
-
-
|
72
|
-
|
78
|
+
- 1
|
79
|
+
- 3
|
80
|
+
- 1
|
81
|
+
version: 1.3.1
|
73
82
|
requirements: []
|
74
83
|
|
75
84
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.3.
|
85
|
+
rubygems_version: 1.3.7
|
77
86
|
signing_key:
|
78
87
|
specification_version: 3
|
79
88
|
summary: "A fork of workflow: a finite-state-machine-inspired API for modeling and interacting with what we tend to refer to as 'workflow'."
|
80
89
|
test_files:
|
90
|
+
- test/without_active_record_test.rb
|
81
91
|
- test/couchtiny_example.rb
|
82
92
|
- test/main_test.rb
|
83
|
-
- test/readme_example.rb
|
84
93
|
- test/test_helper.rb
|
85
|
-
- test/
|
94
|
+
- test/readme_example.rb
|