fromage 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fromage/version.rb +1 -1
- data/lib/mongoid/fromage.rb +13 -13
- metadata +2 -2
data/lib/fromage/version.rb
CHANGED
data/lib/mongoid/fromage.rb
CHANGED
@@ -9,7 +9,7 @@ module Mongoid
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
class_attribute :fromage_defaults
|
12
|
-
field :roles, type:
|
12
|
+
field :roles, type: Set, default: lambda { Array(self.fromage_defaults) }
|
13
13
|
validate :roles, :valid_roles?
|
14
14
|
|
15
15
|
scope :any_role, lambda {|*role| any_in(:roles => role)}
|
@@ -21,31 +21,31 @@ module Mongoid
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def add_role!(*args)
|
24
|
-
|
25
|
-
|
24
|
+
add_role(*args)
|
25
|
+
save
|
26
26
|
end
|
27
27
|
|
28
28
|
def remove_role(role)
|
29
|
-
self.roles
|
29
|
+
self.roles = self.roles.delete(role)
|
30
30
|
end
|
31
31
|
|
32
32
|
def remove_role!(role)
|
33
|
-
|
34
|
-
|
33
|
+
remove_role(role)
|
34
|
+
save
|
35
35
|
end
|
36
36
|
|
37
37
|
def has_role?(role)
|
38
|
-
|
38
|
+
roles.include? role
|
39
39
|
end
|
40
40
|
|
41
41
|
def has_roles?(*args)
|
42
|
-
args.all? {|role|
|
42
|
+
args.all? {|role| has_role?(role) }
|
43
43
|
end
|
44
44
|
|
45
45
|
protected
|
46
46
|
|
47
47
|
def valid_roles?
|
48
|
-
if (
|
48
|
+
if (roles - self.class.roles).any?
|
49
49
|
errors.add(:roles, :not_included)
|
50
50
|
end
|
51
51
|
end
|
@@ -60,17 +60,17 @@ module Mongoid
|
|
60
60
|
self.roles = argv
|
61
61
|
|
62
62
|
# define helper methods for roles
|
63
|
-
|
63
|
+
roles.each do |role|
|
64
64
|
define_method "#{role}?" do
|
65
|
-
|
65
|
+
has_role? role
|
66
66
|
end
|
67
67
|
|
68
68
|
define_method "#{role}!" do
|
69
|
-
|
69
|
+
add_role!(role)
|
70
70
|
end
|
71
71
|
|
72
72
|
define_method "un_#{role}!" do
|
73
|
-
|
73
|
+
remove_role!(role)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fromage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2013-02-
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|