maintain 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/maintain.rb +25 -24
- data/maintain.gemspec +6 -4
- data/spec/integer_spec.rb +5 -1
- data/spec/subclass_spec.rb +37 -0
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/maintain.rb
CHANGED
@@ -45,35 +45,28 @@ module Maintain
|
|
45
45
|
class_eval <<-EOC, __FILE__
|
46
46
|
def #{attribute}=(value)
|
47
47
|
# Find the maintainer on this attribute so we can use it to set values.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
maintainer = self.class.maintainers[:#{attribute}]
|
49
|
+
changed = #{attribute} != value
|
50
|
+
# Run the exit hook if we're changing the value
|
51
|
+
maintainer.hook(:exit, #{attribute}.name, self) if changed
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
# Then set the value itself. Maintainer::State will return the value you set,
|
54
|
+
# so if we're setting to nil we get rid of the attribute entirely - it's not
|
55
|
+
# needed and we want the getter to return nil in that case.
|
56
|
+
#{attribute}.set_value(value)
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# Last but not least, run the enter hooks for the new value - cause that's how
|
64
|
-
# we do.
|
65
|
-
maintainer.hook(:enter, #{attribute}.name, self) if changed
|
66
|
-
else
|
67
|
-
@#{attribute} = value
|
58
|
+
# Allow the back end to write values in an ORM-specific way
|
59
|
+
if maintainer.back_end
|
60
|
+
maintainer.back_end.write(self, :#{attribute}, #{attribute}.value)
|
68
61
|
end
|
62
|
+
|
63
|
+
# Last but not least, run the enter hooks for the new value - cause that's how
|
64
|
+
# we do.
|
65
|
+
maintainer.hook(:enter, #{attribute}.name, self) if changed
|
69
66
|
end
|
70
67
|
|
71
68
|
def #{attribute}
|
72
|
-
|
73
|
-
@#{attribute} ||= maintainer.value(self)
|
74
|
-
else
|
75
|
-
@#{attribute}
|
76
|
-
end
|
69
|
+
@#{attribute} ||= self.class.maintainers[:#{attribute}].value(self)
|
77
70
|
end
|
78
71
|
EOC
|
79
72
|
|
@@ -85,7 +78,15 @@ module Maintain
|
|
85
78
|
alias :maintains :maintain
|
86
79
|
|
87
80
|
def maintainers #:nodoc:
|
88
|
-
@maintainers ||=
|
81
|
+
@maintainers ||= begin
|
82
|
+
maintainers = {}
|
83
|
+
superk = superclass
|
84
|
+
while superk.respond_to?(:maintainers)
|
85
|
+
maintainers.merge!(superk.maintainers)
|
86
|
+
superk = superk.superclass
|
87
|
+
end
|
88
|
+
maintainers
|
89
|
+
end
|
89
90
|
end
|
90
91
|
|
91
92
|
if File.file?(version_path = File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
data/maintain.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{maintain}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
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 = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-28}
|
13
13
|
s.description = %q{
|
14
14
|
Maintain is a simple state machine mixin for Ruby objects. It supports comparisons, bitmasks,
|
15
15
|
and hooks that really work. It can be used for multiple attributes and will always do its best to
|
@@ -47,7 +47,8 @@ Gem::Specification.new do |s|
|
|
47
47
|
"spec/object_spec.rb",
|
48
48
|
"spec/proxy_spec.rb",
|
49
49
|
"spec/setting_state_spec.rb",
|
50
|
-
"spec/spec.opts"
|
50
|
+
"spec/spec.opts",
|
51
|
+
"spec/subclass_spec.rb"
|
51
52
|
]
|
52
53
|
s.homepage = %q{http://github.com/flipsasser/maintain}
|
53
54
|
s.require_paths = ["lib"]
|
@@ -65,7 +66,8 @@ Gem::Specification.new do |s|
|
|
65
66
|
"spec/maintain_spec.rb",
|
66
67
|
"spec/object_spec.rb",
|
67
68
|
"spec/proxy_spec.rb",
|
68
|
-
"spec/setting_state_spec.rb"
|
69
|
+
"spec/setting_state_spec.rb",
|
70
|
+
"spec/subclass_spec.rb"
|
69
71
|
]
|
70
72
|
|
71
73
|
if s.respond_to? :specification_version then
|
data/spec/integer_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Maintain do
|
|
13
13
|
before :each do
|
14
14
|
MaintainTest.maintain :kind, :integer => true do
|
15
15
|
state :man, 1
|
16
|
-
state :woman, 2
|
16
|
+
state :woman, 2, :default => true
|
17
17
|
state :none, 3
|
18
18
|
end
|
19
19
|
@maintainer = MaintainTest.new
|
@@ -24,6 +24,10 @@ describe Maintain do
|
|
24
24
|
@maintainer.none?.should be_true
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should handle defaults just fine" do
|
28
|
+
@maintainer.woman?.should be_true
|
29
|
+
end
|
30
|
+
|
27
31
|
it "should return valid names, too" do
|
28
32
|
@maintainer.kind = :woman
|
29
33
|
@maintainer.kind.should == 2
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Basic class method specs
|
2
|
+
|
3
|
+
require 'lib/maintain'
|
4
|
+
|
5
|
+
describe Maintain do
|
6
|
+
before :each do
|
7
|
+
class ::MaintainTest
|
8
|
+
attr_accessor :existant_attribute
|
9
|
+
extend Maintain
|
10
|
+
end
|
11
|
+
|
12
|
+
class ::MaintainTestSubclass < ::MaintainTest; end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should inherit maintainers from parent classes" do
|
16
|
+
MaintainTest.maintain :status do
|
17
|
+
state :new
|
18
|
+
state :old
|
19
|
+
end
|
20
|
+
MaintainTestSubclass.maintainers[:status].should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not propagate maintainers up the class system" do
|
24
|
+
MaintainTest.maintain :status do
|
25
|
+
state :new
|
26
|
+
state :old
|
27
|
+
end
|
28
|
+
MaintainTestSubclass.maintain :foo do
|
29
|
+
state :bar
|
30
|
+
state :baz
|
31
|
+
end
|
32
|
+
MaintainTest.maintainers[:foo].should be_nil
|
33
|
+
MaintainTestSubclass.maintainers[:status].should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maintain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flip Sasser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-28 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- spec/proxy_spec.rb
|
57
57
|
- spec/setting_state_spec.rb
|
58
58
|
- spec/spec.opts
|
59
|
+
- spec/subclass_spec.rb
|
59
60
|
has_rdoc: true
|
60
61
|
homepage: http://github.com/flipsasser/maintain
|
61
62
|
licenses: []
|
@@ -103,3 +104,4 @@ test_files:
|
|
103
104
|
- spec/object_spec.rb
|
104
105
|
- spec/proxy_spec.rb
|
105
106
|
- spec/setting_state_spec.rb
|
107
|
+
- spec/subclass_spec.rb
|