bitswitch 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bitswitch/version.rb +1 -1
- data/lib/bitswitch.rb +14 -3
- metadata +2 -2
data/lib/bitswitch/version.rb
CHANGED
data/lib/bitswitch.rb
CHANGED
@@ -35,10 +35,11 @@ class BitSwitch
|
|
35
35
|
|
36
36
|
# Set a bit
|
37
37
|
def []=(bit, val)
|
38
|
-
val = val
|
38
|
+
val = val == true if val.is_a?(TrueClass)
|
39
|
+
val = val > 0 if val.is_a?(Fixnum)
|
39
40
|
|
40
41
|
# If a string representation of a bit was provided get the numerical
|
41
|
-
bit.to_s if bit.is_a?(Symbol)
|
42
|
+
bit = bit.to_s if bit.is_a?(Symbol)
|
42
43
|
bit = @labels.invert[bit] if bit.is_a?(String)
|
43
44
|
|
44
45
|
# If nil return false
|
@@ -56,7 +57,7 @@ class BitSwitch
|
|
56
57
|
def [](bit)
|
57
58
|
|
58
59
|
# If a string representation of a bit was provided get the numerical
|
59
|
-
bit.to_s if bit.is_a?(Symbol)
|
60
|
+
bit = bit.to_s if bit.is_a?(Symbol)
|
60
61
|
bit = @labels.invert[bit] if bit.is_a?(String)
|
61
62
|
|
62
63
|
# If nil return false
|
@@ -109,6 +110,16 @@ class BitSwitch
|
|
109
110
|
# Return the serialized BitSwitch
|
110
111
|
serialized
|
111
112
|
end
|
113
|
+
|
114
|
+
# Method missing for args access
|
115
|
+
def method_missing(method, *args)
|
116
|
+
if method[-1] == '='
|
117
|
+
method = method[0..-2]
|
118
|
+
return self[method] = args.first
|
119
|
+
end
|
120
|
+
|
121
|
+
self[method]
|
122
|
+
end
|
112
123
|
end
|
113
124
|
|
114
125
|
# Convert Fixnum to Switch
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitswitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Have you ever wanted to store multiple true/false values in your database,
|
15
15
|
but annoyed with how many fields your tables have, then BitSwitcher is good for
|