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 +1 -1
- data/lib/generators/data_mapper/roles/roles_generator.rb +30 -6
- data/roles_data_mapper.gemspec +44 -46
- metadata +5 -6
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
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 :
|
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
|
-
|
31
|
+
rescue Exeption => e
|
32
|
+
logger.debug"Error: #{e.message}"
|
23
33
|
end
|
24
|
-
|
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
|
-
|
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}
|
data/roles_data_mapper.gemspec
CHANGED
@@ -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
|
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.
|
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-
|
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
|
-
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
-
|
9
|
-
version: 0.2.
|
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-
|
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
|
-
|
214
|
+
rdoc_options: []
|
215
|
+
|
217
216
|
require_paths:
|
218
217
|
- lib
|
219
218
|
required_ruby_version: !ruby/object:Gem::Requirement
|