maintain 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/maintain/bitmask_value.rb +1 -1
- data/lib/maintain/value.rb +6 -2
- data/spec/active_record_spec.rb +15 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -12,7 +12,7 @@ module Maintain
|
|
12
12
|
|
13
13
|
protected
|
14
14
|
def bitmask_for(states)
|
15
|
-
Array(states).map{|value| value_for(value) }.sort.inject(0) {|total, mask| total | mask }
|
15
|
+
Array(states).compact.map{|value| value_for(value) }.sort.inject(0) {|total, mask| total | mask.to_i }
|
16
16
|
end
|
17
17
|
|
18
18
|
def compare_value
|
data/lib/maintain/value.rb
CHANGED
@@ -100,8 +100,12 @@ module Maintain
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def state_value_for(state, value)
|
103
|
-
if (state.is_a?(String) || state.is_a?(Symbol))
|
104
|
-
state_hash[
|
103
|
+
if (state.is_a?(String) || state.is_a?(Symbol))
|
104
|
+
if !state.to_s.strip.empty? && state_hash = @state.states[state.to_sym]
|
105
|
+
state_hash[value]
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
105
109
|
else
|
106
110
|
state
|
107
111
|
end
|
data/spec/active_record_spec.rb
CHANGED
@@ -97,6 +97,21 @@ if proceed
|
|
97
97
|
ActiveMaintainTest.last.permissions.add?.should be_true
|
98
98
|
ActiveMaintainTest.last.permissions.delete?.should be_true
|
99
99
|
end
|
100
|
+
|
101
|
+
it "should allow me to set a blank string as bitmask values" do
|
102
|
+
active_maintain_test = ActiveMaintainTest.create(:permissions => '')
|
103
|
+
ActiveMaintainTest.last.permissions.should == 0
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow me to set an empty array as bitmask values" do
|
107
|
+
active_maintain_test = ActiveMaintainTest.create(:permissions => [])
|
108
|
+
ActiveMaintainTest.last.permissions.should == 0
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should allow me to set an array with empty strings as bitmask values" do
|
112
|
+
active_maintain_test = ActiveMaintainTest.create(:permissions => [''])
|
113
|
+
ActiveMaintainTest.last.permissions.should == 0
|
114
|
+
end
|
100
115
|
end
|
101
116
|
|
102
117
|
describe "named_scopes" do
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flip Sasser
|