maintain 0.1.0 → 0.1.1

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/.gitignore CHANGED
@@ -1 +1,2 @@
1
- coverage/
1
+ coverage/
2
+ *.gem
data/README.markdown CHANGED
@@ -61,36 +61,41 @@ You could also do:
61
61
 
62
62
  Foo.new.state > old #=> true
63
63
 
64
- Bitmasking
64
+ Hooks
65
65
  -
66
66
 
67
- Sometimes you need to store a simple combination of values. Sure, you could add individual columns for each value to your
68
- relational database - or you could implement a single bitmask column:
67
+ **Maintain** can hook into state entry and exit, and provides a number of mechanisms for doing so:
68
+
69
+ class Foo < ActiveRecord::Base
70
+ maintains :state do
71
+ state :active, :enter => :activated
72
+ state :inactive, :exit => lambda { self.bar.baz! }
73
+ end
74
+
75
+ def activated
76
+ puts "I'm alive!"
77
+ end
78
+ end
79
+
80
+ Of course, maybe that's not your style. Why not try this?
69
81
 
70
82
  class Foo
71
83
  extend Maintain
72
- maintains :state, :bitmask => true do
73
- # NOTE: Maintain will try to infer a bitmask value if you do not provid an integer here,
74
- # but if you don't -- and you re-order your state calls later -- all stored bitmasks will
75
- # be invalidated. You have been warned.
76
- state :new, 1
77
- state :old, 2
78
- state :borrowed, 3
79
- state :blue, 4
84
+ maintains :state do
85
+ state :active
86
+ state :inactive
87
+
88
+ on :enter, :active, :activated
89
+ on :exit, :inactive do
90
+ bar.baz!
91
+ end
92
+ end
93
+
94
+ def activated
95
+ puts "I'm alive!"
80
96
  end
81
97
  end
82
-
83
- foo = Foo.new
84
- foo.state #=> nil
85
- foo.state = [:new, :borrowed]
86
- foo.state #=> [:new, :borrowed]
87
- foo.new? #=> true
88
- foo.borrowed? #=> true
89
- foo.blue? #=> false
90
- foo.blue!
91
- foo.blue? #=> true
92
-
93
- # foo.state will boil happily down to an integer when you store it.
98
+
94
99
 
95
100
  Aggregates
96
101
  -
@@ -114,55 +119,49 @@ But why not just add the following?
114
119
  foo.status = :borrowed
115
120
  foo.starts_with_b? #=> true
116
121
 
117
- Named Scopes
122
+ Bitmasking
118
123
  -
119
124
 
120
- **Maintain** knows all about ActiveRecord. Adding states and aggregates will automatically create named scopes on ActiveRecord::Base
121
- subclasses for those states! Check it:
125
+ Sometimes you need to store a simple combination of values. Sure, you could add individual columns for each value to your
126
+ relational database - or you could implement a single bitmask column:
122
127
 
123
- class Foo < ActiveRecord::Base
128
+ class Foo
124
129
  extend Maintain
125
- maintains :state do
126
- state :active
127
- state :inactive
130
+ maintains :state, :bitmask => true do
131
+ # NOTE: Maintain will try to infer a bitmask value if you do not provide an integer here,
132
+ # but if you don't -- and you re-order your state calls later -- all stored bitmasks will
133
+ # be invalidated. You have been warned.
134
+ state :new, 1
135
+ state :old, 2
136
+ state :borrowed, 3
137
+ state :blue, 4
128
138
  end
129
139
  end
130
140
 
131
- Foo.active #=> []
132
- Foo.inactive #=> []
141
+ foo = Foo.new
142
+ foo.state #=> nil
143
+ foo.state = [:new, :borrowed]
144
+ foo.state #=> [:new, :borrowed]
145
+ foo.new? #=> true
146
+ foo.borrowed? #=> true
147
+ foo.blue? #=> false
148
+ foo.blue!
149
+ foo.blue? #=> true
150
+
151
+ # foo.state will boil happily down to an integer when you store it.
133
152
 
134
- Hooks
153
+ Named Scopes
135
154
  -
136
155
 
137
- **Maintain** can hook into state entry and exit, and provides a number of mechanisms for doing so:
156
+ **Maintain** knows all about ActiveRecord - it even extends ActiveRecord::Base by default. So it stands to reason that adding states
157
+ and aggregates will automatically create named scopes on ActiveRecord::Base subclasses for those states! Check it:
138
158
 
139
159
  class Foo < ActiveRecord::Base
140
- maintains :state do
141
- state :active, :enter => :activated
142
- state :inactive, :exit => lambda { self.bar.baz! }
143
- end
144
-
145
- def activated
146
- puts "I'm alive!"
147
- end
148
- end
149
-
150
- Of course, maybe that's not your style. Why not try this?
151
-
152
- class Foo
153
- extend Maintain
154
160
  maintains :state do
155
161
  state :active
156
162
  state :inactive
157
-
158
- enter :active, :activated
159
- exit :inactive do
160
- bar.baz!
161
- end
162
- end
163
-
164
- def activated
165
- puts "I'm alive!"
166
163
  end
167
164
  end
168
-
165
+
166
+ Foo.active #=> []
167
+ Foo.inactive #=> []
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/maintain.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Maintain
2
2
  # We're not really interested in loading anything into memory if we don't need to,
3
3
  # so Maintainer, Value, and the Value subclasses are ignored until they're needed.
4
- autoload(:Maintainer, 'lib/maintain/maintainer')
5
- autoload(:Value, 'lib/maintain/value')
6
- autoload(:BitmaskValue, 'lib/maintain/bitmask_value')
7
- autoload(:IntegerValue, 'lib/maintain/integer_value')
4
+ autoload(:Maintainer, 'maintain/maintainer')
5
+ autoload(:Value, 'maintain/value')
6
+ autoload(:BitmaskValue, 'maintain/bitmask_value')
7
+ autoload(:IntegerValue, 'maintain/integer_value')
8
8
 
9
9
  # The core class method of Maintain. Basic usage is:
10
10
  #
data/maintain.gemspec ADDED
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{maintain}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Flip Sasser"]
12
+ s.date = %q{2010-02-19}
13
+ s.description = %q{
14
+ Maintain is a simple state machine mixin for Ruby objects. It supports comparisons, bitmasks,
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}
19
+ s.extra_rdoc_files = [
20
+ "README.markdown"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/maintain.rb",
28
+ "lib/maintain/bitmask_value.rb",
29
+ "lib/maintain/integer_value.rb",
30
+ "lib/maintain/maintainer.rb",
31
+ "lib/maintain/value.rb",
32
+ "maintain.gemspec",
33
+ "spec/active_record_spec.rb",
34
+ "spec/aggregates_spec.rb",
35
+ "spec/bitwise_spec.rb",
36
+ "spec/comparing_state_spec.rb",
37
+ "spec/defining_states_spec.rb",
38
+ "spec/hooks_spec.rb",
39
+ "spec/integer_spec.rb",
40
+ "spec/maintain_spec.rb",
41
+ "spec/object_spec.rb",
42
+ "spec/proxy_spec.rb",
43
+ "spec/setting_state_spec.rb"
44
+ ]
45
+ s.homepage = %q{http://github.com/flipsasser/maintain}
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.5}
49
+ s.summary = %q{A Ruby state machine that lets your code do the driving}
50
+ s.test_files = [
51
+ "spec/active_record_spec.rb",
52
+ "spec/aggregates_spec.rb",
53
+ "spec/bitwise_spec.rb",
54
+ "spec/comparing_state_spec.rb",
55
+ "spec/defining_states_spec.rb",
56
+ "spec/hooks_spec.rb",
57
+ "spec/integer_spec.rb",
58
+ "spec/maintain_spec.rb",
59
+ "spec/object_spec.rb",
60
+ "spec/proxy_spec.rb",
61
+ "spec/setting_state_spec.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ else
70
+ end
71
+ else
72
+ end
73
+ end
74
+
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flip Sasser
@@ -31,6 +31,7 @@ files:
31
31
  - lib/maintain/integer_value.rb
32
32
  - lib/maintain/maintainer.rb
33
33
  - lib/maintain/value.rb
34
+ - maintain.gemspec
34
35
  - spec/active_record_spec.rb
35
36
  - spec/aggregates_spec.rb
36
37
  - spec/bitwise_spec.rb