roles_mongo_mapper 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -9,12 +9,28 @@ module MongoMapper
9
9
  class_option :strategy, :type => :string, :default => 'role_string',
10
10
  :desc => "Role strategy to use (admin_flag, role_string, roles_string, role_strings, one_role, many_roles, roles_mask)"
11
11
 
12
-
12
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
13
13
  class_option :roles, :type => :array, :default => [], :desc => "Valid roles"
14
14
 
15
15
  def apply_role_strategy
16
- insert_into_model name do
17
- insertion_text
16
+ logger.add_logfile :logfile => logfile if logfile
17
+ logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
18
+
19
+ if !has_model_file?(user_model_name)
20
+ say "User model #{user_model_name} not found", :red
21
+ return
22
+ end
23
+
24
+ begin
25
+ insert_into_model user_model_name, :after => /include MongoMapper::\w+/ do
26
+ insertion_text
27
+ end
28
+
29
+ unless read_model(:user) =~ /use_roles_strategy/
30
+ inject_into_file model_file(:user), "use_roles_strategy :#{strategy}\n\n", :before => "class"
31
+ end
32
+ rescue Exception => e
33
+ logger.debug"Error: #{e.message}"
18
34
  end
19
35
  end
20
36
 
@@ -25,6 +41,14 @@ module MongoMapper
25
41
 
26
42
  include Rails3::Assist::BasicLogger
27
43
 
44
+ def logfile
45
+ options[:logfile]
46
+ end
47
+
48
+ def user_model_name
49
+ name || 'User'
50
+ end
51
+
28
52
  def orm
29
53
  :mongo_mapper
30
54
  end
@@ -50,9 +74,14 @@ module MongoMapper
50
74
  end
51
75
 
52
76
  def roles_statement
77
+ return '' if has_valid_roles_statement?
53
78
  roles ? "valid_roles_are #{roles.join(', ')}" : ''
54
79
  end
55
80
 
81
+ def has_valid_roles_statement?
82
+ !(read_model(user_model_name) =~ /valid_roles_are/).nil?
83
+ end
84
+
56
85
  def insertion_text
57
86
  %Q{include Roles::#{orm.to_s.camelize}
58
87
  #{role_strategy_statement}
@@ -78,36 +78,7 @@ module RoleStrategy::MongoMapper
78
78
 
79
79
  def set_empty_roles
80
80
  self.send("#{role_attribute}=", [])
81
- end
82
- # def role_id_attribute
83
- # "#{role_attribute}_ids".to_sym
84
- # end
85
- #
86
- # # assign roles
87
- # def roles=(*_roles)
88
- # _roles = get_roles(_roles)
89
- # return nil if _roles.none?
90
- #
91
- # role_relations = role_class.find_roles(_roles)
92
- # self.send("#{role_attribute}=", role_relations)
93
- # save
94
- # end
95
- #
96
- # def add_roles(*role_names)
97
- # raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
98
- # role_relations = role_class.find_roles(*role_names)
99
- # self.send(role_attribute) << role_relations
100
- # save
101
- # end
102
- #
103
- # # query assigned roles
104
- # def roles
105
- # self.send(role_attribute)
106
- # end
107
- #
108
- # def roles_list
109
- # [roles].flatten.map{|r| r.name }.compact.to_symbols
110
- # end
81
+ end
111
82
  end
112
83
 
113
84
  extend Roles::Generic::User::Configuration
@@ -1,84 +1,82 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_mongo_mapper}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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-11-24}
12
+ s.date = %q{2010-12-01}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in MongoMapper}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- ".rspec",
23
- "LICENSE",
24
- "README.markdown",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/generators/mongo_mapper/roles/roles_generator.rb",
28
- "lib/roles_mongo_mapper.rb",
29
- "lib/roles_mongo_mapper/base.rb",
30
- "lib/roles_mongo_mapper/embedded_role.rb",
31
- "lib/roles_mongo_mapper/namespaces.rb",
32
- "lib/roles_mongo_mapper/role.rb",
33
- "lib/roles_mongo_mapper/strategy.rb",
34
- "lib/roles_mongo_mapper/strategy/multi.rb",
35
- "lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb",
36
- "lib/roles_mongo_mapper/strategy/multi/many_roles.rb",
37
- "lib/roles_mongo_mapper/strategy/multi/role_strings.rb",
38
- "lib/roles_mongo_mapper/strategy/multi/roles_mask.rb",
39
- "lib/roles_mongo_mapper/strategy/shared.rb",
40
- "lib/roles_mongo_mapper/strategy/single.rb",
41
- "lib/roles_mongo_mapper/strategy/single/admin_flag.rb",
42
- "lib/roles_mongo_mapper/strategy/single/embed_one_role.rb",
43
- "lib/roles_mongo_mapper/strategy/single/one_role.rb",
44
- "lib/roles_mongo_mapper/strategy/single/role_string.rb",
45
- "roles_mongo_mapper.gemspec",
46
- "sandbox/test.rb",
47
- "spec/generator_spec_helper.rb",
48
- "spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
49
- "spec/roles_mongo_mapper/strategy/api_examples.rb",
50
- "spec/roles_mongo_mapper/strategy/hooks.rb",
51
- "spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
52
- "spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
53
- "spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
54
- "spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
55
- "spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
56
- "spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
57
- "spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
58
- "spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
59
- "spec/roles_mongo_mapper/strategy/user_setup.rb",
60
- "spec/spec_helper.rb"
21
+ ".rspec",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/generators/mongo_mapper/roles/roles_generator.rb",
27
+ "lib/roles_mongo_mapper.rb",
28
+ "lib/roles_mongo_mapper/base.rb",
29
+ "lib/roles_mongo_mapper/embedded_role.rb",
30
+ "lib/roles_mongo_mapper/namespaces.rb",
31
+ "lib/roles_mongo_mapper/role.rb",
32
+ "lib/roles_mongo_mapper/strategy.rb",
33
+ "lib/roles_mongo_mapper/strategy/multi.rb",
34
+ "lib/roles_mongo_mapper/strategy/multi/embed_many_roles.rb",
35
+ "lib/roles_mongo_mapper/strategy/multi/many_roles.rb",
36
+ "lib/roles_mongo_mapper/strategy/multi/role_strings.rb",
37
+ "lib/roles_mongo_mapper/strategy/multi/roles_mask.rb",
38
+ "lib/roles_mongo_mapper/strategy/shared.rb",
39
+ "lib/roles_mongo_mapper/strategy/single.rb",
40
+ "lib/roles_mongo_mapper/strategy/single/admin_flag.rb",
41
+ "lib/roles_mongo_mapper/strategy/single/embed_one_role.rb",
42
+ "lib/roles_mongo_mapper/strategy/single/one_role.rb",
43
+ "lib/roles_mongo_mapper/strategy/single/role_string.rb",
44
+ "roles_mongo_mapper.gemspec",
45
+ "sandbox/test.rb",
46
+ "spec/generator_spec_helper.rb",
47
+ "spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
48
+ "spec/roles_mongo_mapper/strategy/api_examples.rb",
49
+ "spec/roles_mongo_mapper/strategy/hooks.rb",
50
+ "spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
51
+ "spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
52
+ "spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
53
+ "spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
54
+ "spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
55
+ "spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
56
+ "spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
57
+ "spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
58
+ "spec/roles_mongo_mapper/strategy/user_setup.rb",
59
+ "spec/spec_helper.rb"
61
60
  ]
62
61
  s.homepage = %q{http://github.com/kristianmandrup/roles_mongo_mapper}
63
- s.rdoc_options = ["--charset=UTF-8"]
64
62
  s.require_paths = ["lib"]
65
63
  s.rubygems_version = %q{1.3.7}
66
64
  s.summary = %q{Implementation of Roles generic API for MongoMapper}
67
65
  s.test_files = [
68
66
  "spec/generator_spec_helper.rb",
69
- "spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
70
- "spec/roles_mongo_mapper/strategy/api_examples.rb",
71
- "spec/roles_mongo_mapper/strategy/hooks.rb",
72
- "spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
73
- "spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
74
- "spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
75
- "spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
76
- "spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
77
- "spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
78
- "spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
79
- "spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
80
- "spec/roles_mongo_mapper/strategy/user_setup.rb",
81
- "spec/spec_helper.rb"
67
+ "spec/roles_mongo_mapper/generators/roles_generator_spec.rb",
68
+ "spec/roles_mongo_mapper/strategy/api_examples.rb",
69
+ "spec/roles_mongo_mapper/strategy/hooks.rb",
70
+ "spec/roles_mongo_mapper/strategy/multi/embed_many_roles_spec.rb",
71
+ "spec/roles_mongo_mapper/strategy/multi/many_roles_spec.rb",
72
+ "spec/roles_mongo_mapper/strategy/multi/role_strings_spec.rb",
73
+ "spec/roles_mongo_mapper/strategy/multi/roles_mask_spec.rb",
74
+ "spec/roles_mongo_mapper/strategy/single/admin_flag_spec.rb",
75
+ "spec/roles_mongo_mapper/strategy/single/embed_one_role_spec.rb",
76
+ "spec/roles_mongo_mapper/strategy/single/one_role_spec.rb",
77
+ "spec/roles_mongo_mapper/strategy/single/role_string_spec.rb",
78
+ "spec/roles_mongo_mapper/strategy/user_setup.rb",
79
+ "spec/spec_helper.rb"
82
80
  ]
83
81
 
84
82
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
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-11-24 00:00:00 +01:00
17
+ date: 2010-12-01 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -161,7 +161,6 @@ extra_rdoc_files:
161
161
  - README.markdown
162
162
  files:
163
163
  - .document
164
- - .gitignore
165
164
  - .rspec
166
165
  - LICENSE
167
166
  - README.markdown
@@ -206,8 +205,8 @@ homepage: http://github.com/kristianmandrup/roles_mongo_mapper
206
205
  licenses: []
207
206
 
208
207
  post_install_message:
209
- rdoc_options:
210
- - --charset=UTF-8
208
+ rdoc_options: []
209
+
211
210
  require_paths:
212
211
  - lib
213
212
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC