fromage 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
  module Fromage
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -9,7 +9,7 @@ module Mongoid
9
9
 
10
10
  included do
11
11
  class_attribute :fromage_defaults
12
- field :roles, type: Array, default: lambda { Array(self.fromage_defaults) }
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
- self.add_role(*args)
25
- self.save
24
+ add_role(*args)
25
+ save
26
26
  end
27
27
 
28
28
  def remove_role(role)
29
- self.roles.tap {|roles| roles.delete(role)}
29
+ self.roles = self.roles.delete(role)
30
30
  end
31
31
 
32
32
  def remove_role!(role)
33
- self.remove_role(role)
34
- self.save
33
+ remove_role(role)
34
+ save
35
35
  end
36
36
 
37
37
  def has_role?(role)
38
- self.roles.include? role
38
+ roles.include? role
39
39
  end
40
40
 
41
41
  def has_roles?(*args)
42
- args.all? {|role| self.has_role?(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 (self.roles - self.class.roles).any?
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
- self.roles.each do |role|
63
+ roles.each do |role|
64
64
  define_method "#{role}?" do
65
- self.has_role? role
65
+ has_role? role
66
66
  end
67
67
 
68
68
  define_method "#{role}!" do
69
- self.add_role!(role)
69
+ add_role!(role)
70
70
  end
71
71
 
72
72
  define_method "un_#{role}!" do
73
- self.remove_role!(role)
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.2.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-11 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec