roles_data_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
@@ -6,28 +6,47 @@ module DataMapper
6
6
  class RolesGenerator < Rails::Generators::NamedBase
7
7
  desc "Add role strategy to a model"
8
8
 
9
+ # argument name
10
+
9
11
  class_option :strategy, :type => :string, :aliases => "-s", :default => 'role_string',
10
12
  :desc => "Role strategy to use (admin_flag, role_string, roles_string, role_strings, one_role, many_roles, roles_mask)"
11
13
 
12
14
 
13
- class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
15
+ class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
16
+ class_option :roles, :type => :array, :default => [], :desc => "Valid roles"
14
17
 
15
18
  def apply_role_strategy
19
+ logger.add_logfile :logfile => logfile if logfile
16
20
  logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
21
+
22
+ if !has_model_file?(user_model_name)
23
+ say "User model #{user_model_name} not found", :red
24
+ return
25
+ end
26
+
17
27
  begin
18
- insert_into_model name do
28
+ insert_into_model name, :after => 'include DataMapper::Resource' do
19
29
  insertion_text
20
30
  end
21
- rescue
22
- say "Model #{name} not found"
31
+ rescue Exeption => e
32
+ logger.debug"Error: #{e.message}"
23
33
  end
24
- end
34
+ end
25
35
 
26
36
  protected
27
37
 
28
38
  extend Rails3::Assist::UseMacro
39
+ include Rails3::Assist::BasicLogger
40
+
29
41
  use_orm :data_mapper
30
- include Rails::Assist::BasicLogging
42
+
43
+ def logfile
44
+ options[:logfile]
45
+ end
46
+
47
+ def user_model_name
48
+ name || 'User'
49
+ end
31
50
 
32
51
  def orm
33
52
  :data_mapper
@@ -54,8 +73,13 @@ module DataMapper
54
73
  end
55
74
 
56
75
  def roles_statement
76
+ return '' if has_valid_roles_statement?
57
77
  roles ? "valid_roles_are #{roles.join(', ')}" : ''
58
78
  end
79
+
80
+ def has_valid_roles_statement?
81
+ !(read_model(user_model_name) =~ /valid_roles_are/).nil?
82
+ end
59
83
 
60
84
  def insertion_text
61
85
  %Q{include Roles::#{orm.to_s.camelize}
@@ -1,72 +1,70 @@
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_data_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-27}
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 DataMapper}
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/data_mapper/roles/roles_generator.rb",
28
- "lib/roles_data_mapper.rb",
29
- "lib/roles_data_mapper/base.rb",
30
- "lib/roles_data_mapper/namespaces.rb",
31
- "lib/roles_data_mapper/role.rb",
32
- "lib/roles_data_mapper/strategy.rb",
33
- "lib/roles_data_mapper/strategy/multi.rb",
34
- "lib/roles_data_mapper/strategy/multi/many_roles.rb",
35
- "lib/roles_data_mapper/strategy/multi/roles_mask.rb",
36
- "lib/roles_data_mapper/strategy/shared.rb",
37
- "lib/roles_data_mapper/strategy/single.rb",
38
- "lib/roles_data_mapper/strategy/single/admin_flag.rb",
39
- "lib/roles_data_mapper/strategy/single/one_role.rb",
40
- "lib/roles_data_mapper/strategy/single/role_string.rb",
41
- "roles_data_mapper.gemspec",
42
- "spec/generator_spec_helper.rb",
43
- "spec/roles_data_mapper/generators/roles_generator_spec.rb",
44
- "spec/roles_data_mapper/strategy/api_examples.rb",
45
- "spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
46
- "spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
47
- "spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
48
- "spec/roles_data_mapper/strategy/single/one_role_spec.rb",
49
- "spec/roles_data_mapper/strategy/single/role_string_spec.rb",
50
- "spec/roles_data_mapper/strategy/user_setup.rb",
51
- "spec/spec_helper.rb",
52
- "tmp/rails/config/routes.rb"
21
+ ".rspec",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/generators/data_mapper/roles/roles_generator.rb",
27
+ "lib/roles_data_mapper.rb",
28
+ "lib/roles_data_mapper/base.rb",
29
+ "lib/roles_data_mapper/namespaces.rb",
30
+ "lib/roles_data_mapper/role.rb",
31
+ "lib/roles_data_mapper/strategy.rb",
32
+ "lib/roles_data_mapper/strategy/multi.rb",
33
+ "lib/roles_data_mapper/strategy/multi/many_roles.rb",
34
+ "lib/roles_data_mapper/strategy/multi/roles_mask.rb",
35
+ "lib/roles_data_mapper/strategy/shared.rb",
36
+ "lib/roles_data_mapper/strategy/single.rb",
37
+ "lib/roles_data_mapper/strategy/single/admin_flag.rb",
38
+ "lib/roles_data_mapper/strategy/single/one_role.rb",
39
+ "lib/roles_data_mapper/strategy/single/role_string.rb",
40
+ "roles_data_mapper.gemspec",
41
+ "spec/generator_spec_helper.rb",
42
+ "spec/roles_data_mapper/generators/roles_generator_spec.rb",
43
+ "spec/roles_data_mapper/strategy/api_examples.rb",
44
+ "spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
45
+ "spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
46
+ "spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
47
+ "spec/roles_data_mapper/strategy/single/one_role_spec.rb",
48
+ "spec/roles_data_mapper/strategy/single/role_string_spec.rb",
49
+ "spec/roles_data_mapper/strategy/user_setup.rb",
50
+ "spec/spec_helper.rb",
51
+ "tmp/rails/config/routes.rb"
53
52
  ]
54
53
  s.homepage = %q{http://github.com/kristianmandrup/roles_for_dm}
55
- s.rdoc_options = ["--charset=UTF-8"]
56
54
  s.require_paths = ["lib"]
57
55
  s.rubygems_version = %q{1.3.7}
58
56
  s.summary = %q{Implementation of Roles generic API for DataMapper}
59
57
  s.test_files = [
60
58
  "spec/generator_spec_helper.rb",
61
- "spec/roles_data_mapper/generators/roles_generator_spec.rb",
62
- "spec/roles_data_mapper/strategy/api_examples.rb",
63
- "spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
64
- "spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
65
- "spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
66
- "spec/roles_data_mapper/strategy/single/one_role_spec.rb",
67
- "spec/roles_data_mapper/strategy/single/role_string_spec.rb",
68
- "spec/roles_data_mapper/strategy/user_setup.rb",
69
- "spec/spec_helper.rb"
59
+ "spec/roles_data_mapper/generators/roles_generator_spec.rb",
60
+ "spec/roles_data_mapper/strategy/api_examples.rb",
61
+ "spec/roles_data_mapper/strategy/multi/many_roles_spec.rb",
62
+ "spec/roles_data_mapper/strategy/multi/roles_mask_spec.rb",
63
+ "spec/roles_data_mapper/strategy/single/admin_flag_spec.rb",
64
+ "spec/roles_data_mapper/strategy/single/one_role_spec.rb",
65
+ "spec/roles_data_mapper/strategy/single/role_string_spec.rb",
66
+ "spec/roles_data_mapper/strategy/user_setup.rb",
67
+ "spec/spec_helper.rb"
70
68
  ]
71
69
 
72
70
  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-27 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
@@ -175,7 +175,6 @@ extra_rdoc_files:
175
175
  - README.markdown
176
176
  files:
177
177
  - .document
178
- - .gitignore
179
178
  - .rspec
180
179
  - LICENSE
181
180
  - README.markdown
@@ -212,8 +211,8 @@ homepage: http://github.com/kristianmandrup/roles_for_dm
212
211
  licenses: []
213
212
 
214
213
  post_install_message:
215
- rdoc_options:
216
- - --charset=UTF-8
214
+ rdoc_options: []
215
+
217
216
  require_paths:
218
217
  - lib
219
218
  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