maintain 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.8
data/lib/maintain.rb CHANGED
@@ -70,6 +70,15 @@ module Maintain
70
70
  end
71
71
  EOC
72
72
 
73
+ class_eval <<-EOC, __FILE__
74
+ class << self
75
+ def maintain_#{attribute}
76
+ @#{attribute} ||= maintainers[:#{attribute}].states.sort{|a, b| (a[1][:compare_value] || a[1][:value]) <=> (b[1][:compare_value] || b[1][:value]) }.map{|key, value| key == value[:value] ? key : [key, value[:value]]}
77
+ end
78
+ #{"alias :#{attribute} :maintain_#{attribute}" unless respond_to?(attribute)}
79
+ end
80
+ EOC
81
+
73
82
  # Last! Not least! Save our maintainer directly on this class. We'll use it in our setters (as in above)
74
83
  # and we'll also modify it instead of replacing it outright, so subclasses or mixins can extend functionality
75
84
  # without replacing it.
@@ -0,0 +1,44 @@
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
+ MaintainTest.maintain :state do
12
+ state :new
13
+ state :overdue
14
+ state :closed
15
+ end
16
+ end
17
+
18
+ it "should provide a hash of key/value stores" do
19
+ MaintainTest.state.should == [:new, :overdue, :closed]
20
+ end
21
+
22
+ it "should provide a hash of key/value stores in an Integer case, too" do
23
+ MaintainTest.maintain :state_two, :integer => true do
24
+ state :new, 1
25
+ state :overdue, 2
26
+ state :closed, 3
27
+ end
28
+ MaintainTest.state_two.should == [[:new, 1], [:overdue, 2], [:closed, 3]]
29
+ end
30
+
31
+ it "should not overwrite existing class methods" do
32
+ def MaintainTest.foo
33
+ "foo"
34
+ end
35
+
36
+ MaintainTest.maintain :foo do
37
+ state :new
38
+ state :overdue
39
+ state :closed
40
+ end
41
+ MaintainTest.foo.should == "foo"
42
+ MaintainTest.maintain_foo.should == [:new, :overdue, :closed]
43
+ end
44
+ 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: 27
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 8
10
+ version: 0.2.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser
@@ -46,6 +46,7 @@ files:
46
46
  - spec/active_record_spec.rb
47
47
  - spec/aggregates_spec.rb
48
48
  - spec/bitwise_spec.rb
49
+ - spec/class_methods_spec.rb
49
50
  - spec/comparing_state_spec.rb
50
51
  - spec/data_mapper_spec.rb
51
52
  - spec/defining_states_spec.rb
@@ -95,6 +96,7 @@ test_files:
95
96
  - spec/active_record_spec.rb
96
97
  - spec/aggregates_spec.rb
97
98
  - spec/bitwise_spec.rb
99
+ - spec/class_methods_spec.rb
98
100
  - spec/comparing_state_spec.rb
99
101
  - spec/data_mapper_spec.rb
100
102
  - spec/defining_states_spec.rb