reallycare_utils 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/reallycare_utils/bitmask.rb +42 -1
- data/lib/reallycare_utils/version.rb +1 -1
- metadata +1 -1
@@ -16,7 +16,7 @@ module ReallycareUtils
|
|
16
16
|
end
|
17
17
|
|
18
18
|
define_method("has_#{attribute}_#{value_name}?".to_sym) do
|
19
|
-
(self["#{attribute}"]
|
19
|
+
((self["#{attribute}"] || 0 )[i]) != 0
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -34,4 +34,45 @@ module ReallycareUtils
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
if __FILE__ == $0
|
37
38
|
|
39
|
+
class FakeActiveRecord
|
40
|
+
def [](value)
|
41
|
+
instance_variable_get(('@'+value).to_sym)
|
42
|
+
end
|
43
|
+
|
44
|
+
def []=(value, value2)
|
45
|
+
instance_variable_set(('@'+value).to_sym, value2)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class User < FakeActiveRecord
|
50
|
+
include ReallycareUtils::Bitmask
|
51
|
+
|
52
|
+
has_bitmasks :status => [:verified, :locked_out], :role => [:admin, :staff]
|
53
|
+
end
|
54
|
+
|
55
|
+
class Angel < FakeActiveRecord
|
56
|
+
include ReallycareUtils::Bitmask
|
57
|
+
has_bitmasks :status => [:pending, :approved]
|
58
|
+
end
|
59
|
+
|
60
|
+
if __FILE__ == $0
|
61
|
+
u = User.new
|
62
|
+
u.add_status_verified
|
63
|
+
puts "#{u.has_role_staff?} should be false" if u.has_role_staff?
|
64
|
+
u.add_role_staff
|
65
|
+
puts "#{u.show_role_flags} should be staff" unless u.show_role_flags == [:staff]
|
66
|
+
puts "#{u.show_status_flags} should be verified" unless u.show_status_flags == [:verified]
|
67
|
+
puts "#{u.has_status_verified?} should be true" unless u.has_status_verified?
|
68
|
+
puts "#{u.has_status_locked_out?} should be false" if u.has_status_locked_out?
|
69
|
+
u.add_status_locked_out
|
70
|
+
puts "#{u.show_status_flags} should be verified and locked_out" unless u.show_status_flags == [:verified, :locked_out]
|
71
|
+
u.remove_status_verified
|
72
|
+
puts "#{u.show_status_flags} should be locked_out" unless u.show_status_flags == [:locked_out]
|
73
|
+
a = Angel.new
|
74
|
+
a.add_status_pending
|
75
|
+
puts "#{a.show_status_flags} should be pending" unless a.show_status_flags == [:pending]
|
76
|
+
puts "Success!"
|
77
|
+
end
|
78
|
+
end
|