roles_mongoid 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -18,15 +18,22 @@ module Mongoid
18
18
  logger.add_logfile :logfile => logfile if logfile
19
19
  logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
20
20
 
21
- say "User model #{user_model_name} not found", :red if !has_model_file?(user_model_name)
22
-
23
- insert_into_model user_model_name, :after => /include Mongoid::\w+/ do
24
- insertion_text
25
- end
26
-
27
- unless read_model(:user) =~ /use_roles_strategy/
28
- inject_into_file model_file(:user), "use_roles_strategy :#{strategy}\n\n", :before => "class"
29
- end
21
+ if !has_model_file?(user_model_name)
22
+ say "User model #{user_model_name} not found", :red
23
+ return
24
+ end
25
+
26
+ begin
27
+ insert_into_model user_model_name, :after => /include Mongoid::\w+/ do
28
+ insertion_text
29
+ end
30
+
31
+ unless read_model(:user) =~ /use_roles_strategy/
32
+ inject_into_file model_file(:user), "use_roles_strategy :#{strategy}\n\n", :before => "class"
33
+ end
34
+ rescue Exception => e
35
+ logger.debug"Error: #{e.message}"
36
+ end
30
37
  end
31
38
 
32
39
  protected
@@ -2,8 +2,11 @@ module Roles::Base
2
2
  def valid_roles_are(*role_list)
3
3
  strategy_class.valid_roles = role_list.to_symbols
4
4
  if role_class_name
5
- role_list.each do |name|
6
- role_class_name.create(:name => name.to_s)
5
+ role_list.each do |name|
6
+ begin
7
+ role_class_name.create(:name => name.to_s)
8
+ rescue
9
+ end
7
10
  end
8
11
  end
9
12
  end
@@ -16,6 +19,8 @@ class Role
16
19
 
17
20
  # references_many :users, :class_name => 'User', :stored_as => :array
18
21
 
22
+ validates_uniqueness_of :name
23
+
19
24
  class << self
20
25
  def find_roles(*role_names)
21
26
  where(:name.in => role_names.flatten).to_a
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_mongoid}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-12-01}
12
+ s.date = %q{2010-12-21}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in Mongoid}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-01 00:00:00 +01:00
17
+ date: 2010-12-21 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency