maintain 0.2.18 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/README.markdown +6 -0
- data/VERSION +1 -1
- data/lib/maintain/backend/active_record.rb +9 -9
- data/lib/maintain/maintainer.rb +10 -9
- data/maintain.gemspec +10 -12
- metadata +3 -2
data/CHANGES
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
0.2.19
|
2
|
+
* Added :force option to state and aggregate definitions, allowing you
|
3
|
+
to force a method overwrite
|
4
|
+
* Added an attribute_name alias to named scopes in the ActiveRecord
|
5
|
+
backend, since Rails 3.1 has eaten up a number of previously
|
6
|
+
usable state names
|
7
|
+
|
8
|
+
0.2.18
|
9
|
+
* Ruby 1.9.2 and Rails 3.1 compatibility updates (no API changes)
|
data/README.markdown
CHANGED
@@ -39,6 +39,12 @@ But wait! What if you've already defined "new?" on the Foo class? Not to worry,
|
|
39
39
|
|
40
40
|
foo.state.new?
|
41
41
|
|
42
|
+
**UPDATE:** what happens when you *want* Maintain to step on your toes? You can add an optionally add:
|
43
|
+
|
44
|
+
state :new, :force => true
|
45
|
+
|
46
|
+
...and Maintain will make sure your methods get added, even if it overwrites a previous method.
|
47
|
+
|
42
48
|
Comparisons
|
43
49
|
-
|
44
50
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.19
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Maintain
|
2
2
|
module Backend
|
3
3
|
class ActiveRecord < Maintain::Backend::Base
|
4
|
-
def aggregate(maintainee, name, attribute, states)
|
4
|
+
def aggregate(maintainee, name, attribute, states, options = {})
|
5
5
|
# named_scope will handle the array of states as "IN" in SQL
|
6
|
-
state(maintainee, name, attribute, states, false)
|
6
|
+
state(maintainee, name, attribute, states, options.merge(:dirty => false))
|
7
7
|
end
|
8
8
|
|
9
9
|
def on(maintainee, attribute, event, state, method, options)
|
@@ -35,14 +35,14 @@ module Maintain
|
|
35
35
|
instance.read_attribute(attribute)
|
36
36
|
end
|
37
37
|
|
38
|
-
def state(maintainee, name, attribute, value,
|
38
|
+
def state(maintainee, name, attribute, value, options = {})
|
39
|
+
options = {:dirty => true}.merge(options)
|
39
40
|
conditions = {:conditions => {attribute => value}}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if dirty
|
41
|
+
puts "NAMING SCOPE: #{name} with #{conditions.inspect} "
|
42
|
+
named_scope_method = defined?(::ActiveRecord::VERSION) && ::ActiveRecord::VERSION::STRING >= '3' ? :scope : :named_scope
|
43
|
+
maintainee.send(named_scope_method, name, conditions) if !maintainee.respond_to?(name) || options[:force]
|
44
|
+
maintainee.send(named_scope_method, "#{attribute}_#{name}", conditions)
|
45
|
+
if options[:dirty]
|
46
46
|
maintainee.class_eval <<-dirty_tracker
|
47
47
|
def #{attribute}_was_#{name}?
|
48
48
|
#{attribute}_was == self.class.maintainers[:#{attribute}].value(self).value_for(:#{name})
|
data/lib/maintain/maintainer.rb
CHANGED
@@ -3,11 +3,12 @@ module Maintain
|
|
3
3
|
class Maintainer
|
4
4
|
attr_reader :back_end
|
5
5
|
|
6
|
-
def aggregate(name, options)
|
7
|
-
if
|
8
|
-
options =
|
6
|
+
def aggregate(name, conditions, options = {})
|
7
|
+
if conditions.is_a?(Hash) && conditions.has_key?(:as)
|
8
|
+
options = conditions
|
9
|
+
conditions = options[:as]
|
9
10
|
end
|
10
|
-
aggregates[name] =
|
11
|
+
aggregates[name] = conditions
|
11
12
|
# Now we're going to add proxies to test for state being in this aggregate. Don't create
|
12
13
|
# this method unless it doesn't exist.
|
13
14
|
boolean_method = "#{name}?"
|
@@ -22,8 +23,8 @@ module Maintain
|
|
22
23
|
EOC
|
23
24
|
end
|
24
25
|
# Now define the state
|
25
|
-
if back_end
|
26
|
-
back_end.aggregate(maintainee, name, @attribute,
|
26
|
+
if back_end
|
27
|
+
back_end.aggregate(maintainee, name, @attribute, conditions.map{|value| states[value][:value].is_a?(Symbol) ? states[value][:value].to_s : states[value][:value] }, {:force => options[:force]})
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -128,8 +129,8 @@ module Maintain
|
|
128
129
|
value ||= name
|
129
130
|
states[name] = {:compare_value => !bitmask? && value.is_a?(Integer) ? value : @increment, :value => value}
|
130
131
|
@increment += 1
|
131
|
-
if
|
132
|
-
back_end.state maintainee, name, @attribute, value.is_a?(Symbol) ? value.to_s : value
|
132
|
+
if back_end
|
133
|
+
back_end.state maintainee, name, @attribute, value.is_a?(Symbol) ? value.to_s : value, :force => options[:force]
|
133
134
|
end
|
134
135
|
|
135
136
|
# We need the states hash to contain the compare_value for this guy before we can set defaults on the bitmask,
|
@@ -154,7 +155,7 @@ module Maintain
|
|
154
155
|
def #{@attribute}_#{boolean_method}
|
155
156
|
#{@attribute}.#{boolean_method}
|
156
157
|
end
|
157
|
-
#{"alias :#{boolean_method} :#{@attribute}_#{boolean_method}" if method_free?(boolean_method)}
|
158
|
+
#{"alias :#{boolean_method} :#{@attribute}_#{boolean_method}" if method_free?(boolean_method) || options[:force]}
|
158
159
|
EOC
|
159
160
|
end
|
160
161
|
|
data/maintain.gemspec
CHANGED
@@ -4,23 +4,20 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.2.
|
7
|
+
s.name = "maintain"
|
8
|
+
s.version = "0.2.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Flip Sasser"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
|
15
|
-
and hooks that really work. It can be used for multiple attributes and will always do its best to
|
16
|
-
stay out of your way and let your code drive the machine, and not vice versa.
|
17
|
-
}
|
18
|
-
s.email = %q{flip@x451.com}
|
12
|
+
s.date = "2011-11-02"
|
13
|
+
s.description = "\n Maintain is a simple state machine mixin for Ruby objects. It supports comparisons, bitmasks,\n and hooks that really work. It can be used for multiple attributes and will always do its best to\n stay out of your way and let your code drive the machine, and not vice versa.\n "
|
14
|
+
s.email = "flip@x451.com"
|
19
15
|
s.extra_rdoc_files = [
|
20
16
|
"README.markdown"
|
21
17
|
]
|
22
18
|
s.files = [
|
23
19
|
".rspec",
|
20
|
+
"CHANGES",
|
24
21
|
"README.markdown",
|
25
22
|
"Rakefile",
|
26
23
|
"VERSION",
|
@@ -49,12 +46,13 @@ Gem::Specification.new do |s|
|
|
49
46
|
"spec/proxy_spec.rb",
|
50
47
|
"spec/setting_state_spec.rb",
|
51
48
|
"spec/spec.opts",
|
49
|
+
"spec/spec_helper.rb",
|
52
50
|
"spec/subclass_spec.rb"
|
53
51
|
]
|
54
|
-
s.homepage =
|
52
|
+
s.homepage = "http://github.com/flipsasser/maintain"
|
55
53
|
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version =
|
57
|
-
s.summary =
|
54
|
+
s.rubygems_version = "1.8.10"
|
55
|
+
s.summary = "A Ruby state machine that lets your code do the driving"
|
58
56
|
|
59
57
|
if s.respond_to? :specification_version then
|
60
58
|
s.specification_version = 3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maintain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-02 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "\n Maintain is a simple state machine mixin for Ruby objects.
|
15
15
|
It supports comparisons, bitmasks,\n and hooks that really work. It can be
|
@@ -22,6 +22,7 @@ extra_rdoc_files:
|
|
22
22
|
- README.markdown
|
23
23
|
files:
|
24
24
|
- .rspec
|
25
|
+
- CHANGES
|
25
26
|
- README.markdown
|
26
27
|
- Rakefile
|
27
28
|
- VERSION
|