maintain 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.2.10
@@ -29,10 +29,10 @@ module Maintain
29
29
  if $2 == '?'
30
30
  self.class.class_eval <<-EOC
31
31
  def #{method}
32
- @value & #{compare.inspect} != 0
32
+ value_for(@value) & #{compare.inspect} != 0
33
33
  end
34
34
  EOC
35
- @value & compare != 0
35
+ value_for(@value) & compare != 0
36
36
  else
37
37
  self.class.class_eval <<-EOC
38
38
  def #{method}
@@ -41,7 +41,11 @@ module Maintain
41
41
 
42
42
  def default(state = nil)
43
43
  if state
44
- @default = state
44
+ if bitmask?
45
+ @default = (@default || 0) | states[state][:value]
46
+ else
47
+ @default = state
48
+ end
45
49
  else
46
50
  @default
47
51
  end
@@ -108,9 +112,6 @@ module Maintain
108
112
  options = value
109
113
  value = nil
110
114
  end
111
- if options.has_key?(:default)
112
- default(name)
113
- end
114
115
  @increment ||= 0
115
116
  if bitmask?
116
117
  unless value.is_a?(Integer)
@@ -127,6 +128,12 @@ module Maintain
127
128
  back_end.state maintainee, name, @attribute, value.is_a?(Symbol) ? value.to_s : value
128
129
  end
129
130
 
131
+ # We need the states hash to contain the compare_value for this guy before we can set defaults on the bitmask,
132
+ # since the default should actually be a bitmask of all possible default states
133
+ if options.has_key?(:default)
134
+ default(name)
135
+ end
136
+
130
137
  # Now we're going to add proxies to test for state. These methods only get added if a
131
138
  # method of their name doesn't already exist.
132
139
  boolean_method = "#{name}?"
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.9"
8
+ s.version = "0.2.10"
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-06-02}
12
+ s.date = %q{2011-06-03}
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
data/spec/bitwise_spec.rb CHANGED
@@ -9,7 +9,20 @@ describe Maintain do
9
9
  end
10
10
  end
11
11
 
12
- describe "bitmask" do
12
+ describe "bitmask", "class methods" do
13
+ it "should allow multiple defaults" do
14
+ MaintainTest.maintain :permissions, :bitmask => true do
15
+ state :edit, 1, :default => true
16
+ state :delete, 2, :default => true
17
+ state :update, 3
18
+ end
19
+ @maintainer = MaintainTest.new
20
+ @maintainer.permissions.edit?.should be_true
21
+ @maintainer.permissions.delete?.should be_true
22
+ end
23
+ end
24
+
25
+ describe "bitmask", "instance methods" do
13
26
  before :each do
14
27
  MaintainTest.maintain :permissions, :bitmask => true do
15
28
  state :edit, 1
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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 9
10
- version: 0.2.9
9
+ - 10
10
+ version: 0.2.10
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-06-02 00:00:00 -04:00
18
+ date: 2011-06-03 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21