roles_for_mongoid 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.markdown CHANGED
@@ -2,11 +2,7 @@
2
2
 
3
3
  A Mongoid implementation of [roles generic](http://github.com/kristianmandrup/roles_generic)
4
4
 
5
- # Install
6
-
7
- <code>gem install roles_mongoid</code>
8
-
9
- ## Status: Sept 6, 2010
5
+ ## Intro
10
6
 
11
7
  Implements the [roles generic](http://github.com/kristianmandrup/roles_generic) Roles API
12
8
  It also implements the following Role strategies:
@@ -18,6 +14,10 @@ It also implements the following Role strategies:
18
14
  * role_string
19
15
  * role_strings
20
16
 
17
+ # Install
18
+
19
+ <code>gem install roles_mongoid</code>
20
+
21
21
  ## Rails generator
22
22
 
23
23
  Might work but needs testing ;)
data/Rakefile CHANGED
@@ -2,45 +2,22 @@ begin
2
2
  require 'jeweler'
3
3
  Jeweler::Tasks.new do |gem|
4
4
  gem.name = "roles_for_mongoid"
5
- gem.summary = %Q{Facilitates adding Roles to your Mongoid user models}
6
- gem.description = %Q{Facilitates adding Roles to your Mongoid user models}
5
+ gem.summary = %Q{Implementation of Roles generic API for Mongoid}
6
+ gem.description = %Q{Makes it easy to set a role strategy on your User model in Mongoid}
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/roles_for_mm"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
11
- gem.add_dependency "mongoid", '~> 2.0.0.beta.17'
12
- gem.add_dependency "require_all", '~> 1.1.0'
13
- gem.add_dependency "sugar-high", '~> 0.2.3'
14
- gem.add_dependency "roles_generic", '~> 0.2.2'
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
10
+ gem.add_development_dependency "rspec", '~> 2.0.0.beta.19'
11
+
12
+ gem.add_dependency "mongoid", '~> 2.0.0.beta.17'
13
+ gem.add_dependency "activesupport", '~> 3.0.0'
14
+ gem.add_dependency "require_all", '~> 1.1.0'
15
+ gem.add_dependency "sugar-high", '~> 0.2.3'
16
+ gem.add_dependency "roles_generic", '~> 0.2.2'
17
+
16
18
  end
17
19
  Jeweler::GemcutterTasks.new
18
20
  rescue LoadError
19
21
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
22
  end
21
23
 
22
- # require 'spec/rake/spectask'
23
- # Spec::Rake::SpecTask.new(:spec) do |spec|
24
- # spec.libs << 'lib' << 'spec'
25
- # spec.spec_files = FileList['spec/**/*_spec.rb']
26
- # end
27
- #
28
- # Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- # spec.libs << 'lib' << 'spec'
30
- # spec.pattern = 'spec/**/*_spec.rb'
31
- # spec.rcov = true
32
- # end
33
- #
34
- # task :spec => :check_dependencies
35
- #
36
- # task :default => :spec
37
- #
38
- # require 'rake/rdoctask'
39
- # Rake::RDocTask.new do |rdoc|
40
- # version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
- #
42
- # rdoc.rdoc_dir = 'rdoc'
43
- # rdoc.title = "roles_for_mm #{version}"
44
- # rdoc.rdoc_files.include('README*')
45
- # rdoc.rdoc_files.include('lib/**/*.rb')
46
- # end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,10 +1,9 @@
1
1
  require 'rails3_artifactor'
2
+ require 'logging_assist'
2
3
 
3
- module RolesModel
4
+ module Mongoid
4
5
  module Generators
5
- class RolesGenerator < Rails::Generators::NamedBase
6
- include Rails3::Assist::Artifact::Model
7
-
6
+ class RolesGenerator < Rails::Generators::NamedBase
8
7
  desc "Add role strategy to a model"
9
8
 
10
9
  class_option :strategy, :type => :string, :aliases => "-s", :default => 'role_string',
@@ -13,14 +12,9 @@ module RolesModel
13
12
 
14
13
  class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
15
14
 
16
- # hook_for :orm
17
-
18
- # def self.source_root
19
- # @source_root ||= File.expand_path("../../templates", __FILE__)
20
- # end
21
-
22
- def apply_role_strategy
23
- self.class.use_orm orm if orm
15
+ def apply_role_strategy
16
+ log.add_logfile
17
+ log.debug "apply_role_strategy for : #{strategy} in model #{name}"
24
18
  insert_into_model name do
25
19
  insertion_text
26
20
  end
@@ -28,6 +22,10 @@ module RolesModel
28
22
 
29
23
  protected
30
24
 
25
+ extend Rails3::Assist::UseMacro
26
+ use_orm :mongoid
27
+ include Rails::Assist::BasicLogging
28
+
31
29
  def orm
32
30
  :mongoid
33
31
  end
@@ -37,27 +35,29 @@ module RolesModel
37
35
  end
38
36
 
39
37
  def roles_to_add
40
- default_roles.concat(options[:roles]).compact.uniq
38
+ @roles_to_add ||= default_roles.concat(options[:roles]).to_symbols.uniq
41
39
  end
42
40
 
43
- def roles
44
- @roles ||= roles_to_add.map{|r| ":#{r}" }
41
+ def roles
42
+ roles_to_add.map{|r| ":#{r}" }
45
43
  end
46
44
 
47
45
  def role_strategy_statement
48
- "strategy :#{strategy}\n"
46
+ "strategy :#{strategy}, :default\n#{role_class_stmt}"
47
+ end
48
+
49
+ def role_class_stmt
50
+ " role_class :role" if [:one_role, :many_roles].include? (strategy.to_sym)
49
51
  end
50
52
 
51
53
  def roles_statement
52
- roles ? "valid_roles #{roles.join(',')}" : ''
54
+ roles ? "valid_roles_are #{roles.join(', ')}" : ''
53
55
  end
54
56
 
55
57
  def insertion_text
56
- %Q{
57
- include Roles::#{orm.to_s.camelize}
58
+ %Q{include Roles::#{orm.to_s.camelize}
58
59
  #{role_strategy_statement}
59
- #{roles_statement}
60
- }
60
+ #{roles_statement}}
61
61
  end
62
62
 
63
63
  def strategy
data/lib/roles_mongoid.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -44,7 +44,7 @@ module RoleStrategy::Mongoid
44
44
  def add_roles(*roles)
45
45
  raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
46
46
  role_relations = role_class.find_roles(*roles)
47
- self.many_roles << role_relations
47
+ self.send(role_attribute) << role_relations
48
48
  save
49
49
  end
50
50
 
@@ -27,10 +27,6 @@ module RoleStrategy::Mongoid
27
27
  end
28
28
 
29
29
  module Implementation
30
- def role_attribute
31
- strategy_class.roles_attribute_name
32
- end
33
-
34
30
  # assign roles
35
31
  def roles=(*new_roles)
36
32
  new_roles = new_roles.flatten.map{|r| r.to_s if valid_role?(r)}.compact
File without changes
File without changes
File without changes
File without changes
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_for_mongoid}
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-09-06}
13
- s.description = %q{Facilitates adding Roles to your Mongoid user models}
12
+ s.date = %q{2010-09-11}
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 = [
16
16
  "LICENSE",
@@ -40,21 +40,27 @@ Gem::Specification.new do |s|
40
40
  "sandbox/roles_assign.rb",
41
41
  "sandbox/single_role.rb",
42
42
  "sandbox/test.rb",
43
+ "spec/generator_spec_helper.rb",
44
+ "spec/generators/roles_generator_spec.rb",
43
45
  "spec/roles_mongoid/admin_flag_spec.rb",
44
46
  "spec/roles_mongoid/many_roles_spec.rb",
45
47
  "spec/roles_mongoid/one_role_spec.rb",
46
48
  "spec/roles_mongoid/role_string_spec.rb",
47
49
  "spec/roles_mongoid/role_strings_spec.rb",
48
50
  "spec/roles_mongoid/roles_mask_spec.rb",
49
- "spec/spec_helper.rb"
51
+ "spec/spec_helper.rb",
52
+ "tmp/rails/app/models/user.rb",
53
+ "tmp/rails/config/routes.rb"
50
54
  ]
51
55
  s.homepage = %q{http://github.com/kristianmandrup/roles_for_mm}
52
56
  s.rdoc_options = ["--charset=UTF-8"]
53
57
  s.require_paths = ["lib"]
54
58
  s.rubygems_version = %q{1.3.7}
55
- s.summary = %q{Facilitates adding Roles to your Mongoid user models}
59
+ s.summary = %q{Implementation of Roles generic API for Mongoid}
56
60
  s.test_files = [
57
- "spec/roles_mongoid/admin_flag_spec.rb",
61
+ "spec/generator_spec_helper.rb",
62
+ "spec/generators/roles_generator_spec.rb",
63
+ "spec/roles_mongoid/admin_flag_spec.rb",
58
64
  "spec/roles_mongoid/many_roles_spec.rb",
59
65
  "spec/roles_mongoid/one_role_spec.rb",
60
66
  "spec/roles_mongoid/role_string_spec.rb",
@@ -68,21 +74,24 @@ Gem::Specification.new do |s|
68
74
  s.specification_version = 3
69
75
 
70
76
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
77
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
72
78
  s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
79
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
73
80
  s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
74
81
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.3"])
75
82
  s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.2"])
76
83
  else
77
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
84
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
78
85
  s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
86
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
79
87
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
80
88
  s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
81
89
  s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
82
90
  end
83
91
  else
84
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
92
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
85
93
  s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
94
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
86
95
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
87
96
  s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
88
97
  s.add_dependency(%q<roles_generic>, ["~> 0.2.2"])
File without changes
File without changes
data/sandbox/test.rb CHANGED
File without changes
@@ -0,0 +1,13 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'rails3_artifactor'
4
+ require 'generator-spec'
5
+ require 'roles_generic'
6
+
7
+ RSpec::Generator.configure do |config|
8
+ config.debug = false
9
+ config.remove_temp_dir = false # true
10
+ config.default_rails_root(__FILE__)
11
+ config.lib = File.dirname(__FILE__) + '/../lib'
12
+ config.logger = :stdout
13
+ end
@@ -0,0 +1,59 @@
1
+ require 'generator_spec_helper'
2
+ require_generator :mongoid => :roles
3
+
4
+ # root_dir = Rails3::Assist::Directory.rails_root
5
+ root_dir = File.join(Rails.application.config.root_dir, 'rails')
6
+
7
+ describe 'role strategy generator: admin_flag' do
8
+ describe 'ORM: mongoid' do
9
+ use_orm :mongoid
10
+
11
+ before :each do
12
+ setup_generator 'mongoid_roles_generator' do
13
+ tests Mongoid::Generators::RolesGenerator
14
+ end
15
+ remove_model :user
16
+ end
17
+
18
+ after :each do
19
+ # remove_model :user
20
+ end
21
+
22
+ it "should configure 'admin_flag' strategy" do
23
+ create_model :user do
24
+ '# content'
25
+ end
26
+ with_generator do |g|
27
+ arguments = "User --strategy admin_flag --roles admin user"
28
+ puts "arguments: #{arguments}"
29
+ g.run_generator arguments.args
30
+ root_dir.should have_model :user do |clazz|
31
+ clazz.should include_module 'Mongoid::Document'
32
+ clazz.should include_module 'Roles::Mongoid'
33
+ puts "clazz: #{clazz}"
34
+ clazz.should have_call :valid_roles_are, :args => ':admin, :guest, :user'
35
+ clazz.should have_call :strategy, :args => ":admin_flag"
36
+ end
37
+ end
38
+ end
39
+
40
+ it "should configure 'one_role' strategy" do
41
+ create_model :user do
42
+ '# content'
43
+ end
44
+ with_generator do |g|
45
+ arguments = "User --strategy one_role --roles admin user"
46
+ puts "arguments: #{arguments}"
47
+ g.run_generator arguments.args
48
+ root_dir.should have_model :user do |clazz|
49
+ clazz.should include_module 'Mongoid::Document'
50
+ clazz.should include_module 'Roles::Mongoid'
51
+ puts "clazz: #{clazz}"
52
+ clazz.should have_call :valid_roles_are, :args => ':admin, :guest, :user'
53
+ clazz.should have_call :strategy, :args => ":one_role"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -17,7 +17,6 @@ Mongoid.database.collections.each do |coll|
17
17
  coll.remove
18
18
  end
19
19
 
20
-
21
20
  RSpec.configure do |config|
22
21
  config.mock_with :mocha
23
22
  # config.before do
@@ -0,0 +1,8 @@
1
+ class User
2
+ include Mongoid::Document
3
+ include Roles::Mongoid
4
+ strategy :admin_flag
5
+
6
+ valid_roles_are :admin, :guest, :user
7
+
8
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
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-09-06 00:00:00 +02:00
17
+ date: 2010-09-11 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
@@ -52,9 +52,24 @@ dependencies:
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
55
- name: require_all
55
+ name: activesupport
56
56
  prerelease: false
57
57
  requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 3
64
+ - 0
65
+ - 0
66
+ version: 3.0.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: require_all
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
58
73
  none: false
59
74
  requirements:
60
75
  - - ~>
@@ -65,11 +80,11 @@ dependencies:
65
80
  - 0
66
81
  version: 1.1.0
67
82
  type: :runtime
68
- version_requirements: *id003
83
+ version_requirements: *id004
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: sugar-high
71
86
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ~>
@@ -80,11 +95,11 @@ dependencies:
80
95
  - 3
81
96
  version: 0.2.3
82
97
  type: :runtime
83
- version_requirements: *id004
98
+ version_requirements: *id005
84
99
  - !ruby/object:Gem::Dependency
85
100
  name: roles_generic
86
101
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
102
+ requirement: &id006 !ruby/object:Gem::Requirement
88
103
  none: false
89
104
  requirements:
90
105
  - - ~>
@@ -95,8 +110,8 @@ dependencies:
95
110
  - 2
96
111
  version: 0.2.2
97
112
  type: :runtime
98
- version_requirements: *id005
99
- description: Facilitates adding Roles to your Mongoid user models
113
+ version_requirements: *id006
114
+ description: Makes it easy to set a role strategy on your User model in Mongoid
100
115
  email: kmandrup@gmail.com
101
116
  executables: []
102
117
 
@@ -129,6 +144,8 @@ files:
129
144
  - sandbox/roles_assign.rb
130
145
  - sandbox/single_role.rb
131
146
  - sandbox/test.rb
147
+ - spec/generator_spec_helper.rb
148
+ - spec/generators/roles_generator_spec.rb
132
149
  - spec/roles_mongoid/admin_flag_spec.rb
133
150
  - spec/roles_mongoid/many_roles_spec.rb
134
151
  - spec/roles_mongoid/one_role_spec.rb
@@ -136,6 +153,8 @@ files:
136
153
  - spec/roles_mongoid/role_strings_spec.rb
137
154
  - spec/roles_mongoid/roles_mask_spec.rb
138
155
  - spec/spec_helper.rb
156
+ - tmp/rails/app/models/user.rb
157
+ - tmp/rails/config/routes.rb
139
158
  has_rdoc: true
140
159
  homepage: http://github.com/kristianmandrup/roles_for_mm
141
160
  licenses: []
@@ -167,8 +186,10 @@ rubyforge_project:
167
186
  rubygems_version: 1.3.7
168
187
  signing_key:
169
188
  specification_version: 3
170
- summary: Facilitates adding Roles to your Mongoid user models
189
+ summary: Implementation of Roles generic API for Mongoid
171
190
  test_files:
191
+ - spec/generator_spec_helper.rb
192
+ - spec/generators/roles_generator_spec.rb
172
193
  - spec/roles_mongoid/admin_flag_spec.rb
173
194
  - spec/roles_mongoid/many_roles_spec.rb
174
195
  - spec/roles_mongoid/one_role_spec.rb