roles_mongoid 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -0,0 +1,11 @@
1
+ class String
2
+ def as_filename
3
+ self.underscore
4
+ end
5
+ end
6
+
7
+ class Symbol
8
+ def as_filename
9
+ self.to_s.underscore
10
+ end
11
+ end
@@ -1,5 +1,6 @@
1
1
  require 'rails3_artifactor'
2
2
  require 'logging_assist'
3
+ require 'generators/mongoid/roles/core_ext'
3
4
 
4
5
  module Mongoid
5
6
  module Generators
@@ -20,30 +21,30 @@ module Mongoid
20
21
 
21
22
  def apply_role_strategy
22
23
  logger.add_logfile :logfile => logfile if logfile
23
- logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
24
+ logger.debug "apply_role_strategy for : #{strategy} in model #{user_file}"
24
25
 
25
26
  if !valid_strategy?
26
- say "Strategy #{strategy} is not currently supported, please try one of #{valid_strategies.join(', ')}", :red
27
+ logger.error "Strategy #{strategy} is not currently supported, please try one of #{valid_strategies.join(', ')}"
27
28
  end
28
29
 
29
- if !has_model_file?(user_class_file)
30
- say "User model #{user_class_file} not found", :red
30
+ if !has_model_file?(user_file)
31
+ logger.error "User model #{user_file} not found"
31
32
  return
32
33
  end
33
34
 
34
- if !is_mongoid_model?(user_class_file)
35
- say "User model #{user_class_file} is not a Mongoid Document", :red
35
+ if !is_mongoid_model?(user_file)
36
+ logger.error "User model #{user_file} is not a Mongoid Document"
36
37
  return
37
38
  end
38
39
 
39
40
  begin
40
- logger.debug "Trying to insert roles code into #{user_class_file}"
41
+ logger.debug "Trying to insert roles code into #{user_file}"
41
42
 
42
- insert_into_model user_class_file, :after => /include Mongoid::\w+/ do
43
+ insert_into_model user_file, :after => /include Mongoid::\w+/ do
43
44
  insertion_text
44
45
  end
45
46
  rescue Exception => e
46
- logger.debug"Error: #{e.message}"
47
+ logger.error "Error: #{e.message}"
47
48
  end
48
49
 
49
50
  copy_role_class if role_class_strategy?
@@ -56,8 +57,12 @@ module Mongoid
56
57
 
57
58
  use_orm :mongoid
58
59
 
59
- def user_class_file
60
- user_class.to_s.underscore
60
+ def user_file
61
+ user_class.as_filename
62
+ end
63
+
64
+ def role_file
65
+ role_class.as_filename
61
66
  end
62
67
 
63
68
  def is_mongoid_model? name
@@ -80,13 +85,17 @@ module Mongoid
80
85
  :mongoid
81
86
  end
82
87
 
88
+ def orm_class
89
+ orm.to_s.camelize
90
+ end
91
+
83
92
  def default_roles
84
93
  [:admin, :guest]
85
94
  end
86
95
 
87
96
  def copy_role_class
88
- logger.debug "copy_role_class: #{role_class.underscore}"
89
- template 'role.rb', "app/models/#{role_class.underscore}.rb"
97
+ logger.debug "generating role model: #{role_file}"
98
+ template 'role.rb', "app/models/#{role_file}.rb"
90
99
  end
91
100
 
92
101
  def roles_to_add
@@ -102,7 +111,7 @@ module Mongoid
102
111
  end
103
112
 
104
113
  def strategy_option_arg
105
- return ", :role_class => :#{role_class.underscore}" if role_class_strategy? && role_class.to_s != 'Role'
114
+ return ", :role_class => '#{role_class}'" if role_class_strategy? && role_class.to_s != 'Role'
106
115
  ''
107
116
  end
108
117
 
@@ -120,7 +129,7 @@ module Mongoid
120
129
  end
121
130
 
122
131
  def insertion_text
123
- %Q{include Roles::#{orm.to_s.camelize}
132
+ %Q{include Roles::#{orm_class}
124
133
  #{role_strategy_statement}
125
134
  #{valid_roles_statement}}
126
135
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_mongoid}
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
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"]
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "README.textile",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "lib/generators/mongoid/roles/core_ext.rb",
28
29
  "lib/generators/mongoid/roles/roles_generator.rb",
29
30
  "lib/generators/mongoid/roles/templates/role.rb",
30
31
  "lib/roles_mongoid.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 3
9
- version: 0.4.3
8
+ - 4
9
+ version: 0.4.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -279,6 +279,7 @@ files:
279
279
  - README.textile
280
280
  - Rakefile
281
281
  - VERSION
282
+ - lib/generators/mongoid/roles/core_ext.rb
282
283
  - lib/generators/mongoid/roles/roles_generator.rb
283
284
  - lib/generators/mongoid/roles/templates/role.rb
284
285
  - lib/roles_mongoid.rb