roles_active_record 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ begin
18
18
  gem.add_development_dependency 'database_cleaner', '>= 0.6'
19
19
  gem.add_development_dependency "rspec", '>= 2.4.1'
20
20
  gem.add_development_dependency "generator-spec", '>= 0.7.3'
21
+ gem.add_development_dependency 'migration_assist', '~> 0.2.0'
21
22
 
22
23
  gem.add_dependency 'roles_generic', '>= 0.3.8'
23
24
  gem.add_dependency 'require_all', '~> 1.2.0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.7
1
+ 0.4.8
@@ -1,5 +1,4 @@
1
- require 'rails3_artifactor'
2
- require 'logging_assist'
1
+ require 'rails_artifactor'
3
2
  require 'generators/active_record/roles/core_ext'
4
3
 
5
4
  module ActiveRecord
@@ -17,26 +16,32 @@ module ActiveRecord
17
16
  class_option :user_role_class, :type => :string, :aliases => "-urc", :default => 'UserRole', :desc => "User Role join class"
18
17
 
19
18
  class_option :default_roles, :type => :boolean, :aliases => "-dr", :default => true, :desc => "Use default roles :admin and :base"
20
- class_option :logfile, :type => :string, :aliases => "-l", :default => nil, :desc => "Logfile location"
19
+ class_option :logfile, :type => :string, :aliases => "-lf", :default => nil, :desc => "Logfile location"
20
+ class_option :logging, :type => :boolean, :aliases => "-l", :default => false, :desc => "Logging on?"
21
21
 
22
22
  source_root File.dirname(__FILE__) + '/templates'
23
23
 
24
24
  def apply_role_strategy
25
- logger.add_logfile :logfile => logfile if logfile
26
- logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
25
+ if logging?
26
+ require 'logging_assist'
27
+ self.class.send :include, Rails3::Assist::BasicLogger
28
+ logger.add_logfile :logfile => logfile if logfile
29
+ end
30
+
31
+ logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}" if logging?
27
32
 
28
33
  if !valid_strategy?
29
- logger.error "Strategy '#{strategy}' is not valid, at least not for Active Record"
34
+ logger.error "Strategy '#{strategy}' is not valid, at least not for Active Record" if logging?
30
35
  return
31
36
  end
32
37
 
33
38
  if !has_model? user_file
34
- logger.error "Could not apply roles strategy to #{user_class} model since the model file was not found"
39
+ logger.error "Could not apply roles strategy to #{user_class} model since the model file was not found" if logging?
35
40
  return
36
41
  end
37
42
 
38
43
  begin
39
- logger.debug "Trying to insert roles code into #{user_class}"
44
+ logger.debug "Trying to insert roles code into #{user_class}" if logging?
40
45
  insert_into_model user_file do
41
46
  insertion_text
42
47
  end
@@ -44,17 +49,19 @@ module ActiveRecord
44
49
  copy_role_models if roles_model_strategy?
45
50
  rescue
46
51
  # logger.debug "Error applying roles strategy to #{name}"
47
- logger.error "Error applying roles strategy to #{user_class}"
52
+ logger.error "Error applying roles strategy to #{user_class}" if logging?
48
53
  end
49
54
  end
50
55
 
51
56
  protected
52
57
 
53
- extend Rails3::Assist::UseMacro
54
-
55
- use_orm :active_record
58
+ extend RailsAssist::UseMacro
56
59
 
57
- include Rails3::Assist::BasicLogger
60
+ use_orm :active_record
61
+
62
+ def logging?
63
+ options[:logging]
64
+ end
58
65
 
59
66
  def user_file
60
67
  user_class.as_filename
@@ -79,12 +86,12 @@ module ActiveRecord
79
86
  end
80
87
 
81
88
  def copy_one_role_model
82
- logger.debug "generating role model for one_role strategy: #{role_file}"
89
+ logger.debug "generating role model for one_role strategy: #{role_file}" if logging?
83
90
  template 'one_role/role.rb', "app/models/#{role_file}.rb"
84
91
  end
85
92
 
86
93
  def copy_many_roles_models
87
- logger.debug "generating role models for many_roles strategy: #{role_file} and #{user_file}"
94
+ logger.debug "generating role models for many_roles strategy: #{role_file} and #{user_file}" if logging?
88
95
 
89
96
  template 'many_roles/role.rb', "app/models/#{role_file}.rb"
90
97
  template 'many_roles/user_role.rb', "app/models/#{user_role_file}.rb"
@@ -1,10 +1,9 @@
1
1
  require 'migration_assist'
2
- require 'logging_assist'
3
2
 
4
3
  module ActiveRecord
5
4
  module Generators
6
5
  class RolesMigrationGenerator < Rails::Generators::NamedBase
7
- include Rails3::Migration::Assist
6
+ include RailsAssist::Migration
8
7
 
9
8
  desc "Generates user role migrations"
10
9
 
@@ -16,6 +15,7 @@ module ActiveRecord
16
15
  class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
17
16
  class_option :default_roles, :type => :boolean, :default => true, :desc => "Use default roles :admin and :base"
18
17
  class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
18
+ class_option :logging, :type => :boolean, :aliases => "-l", :default => false, :desc => "Logging on?"
19
19
  class_option :reverse, :type => :boolean, :alias => "-r", :default => false, :desc => "Create a remove migration for reversing a strategy"
20
20
 
21
21
  def self.source_root
@@ -23,7 +23,12 @@ module ActiveRecord
23
23
  end
24
24
 
25
25
  def main
26
- logger.add_logfile :logfile => logfile if logfile
26
+ if logging?
27
+ require 'logging_assist'
28
+ self.class.send :include, Rails3::Assist::BasicLogger
29
+ logger.add_logfile :logfile => logfile if logfile
30
+ end
31
+
27
32
  valid_strategy?
28
33
  run_migration
29
34
  end
@@ -32,7 +37,7 @@ module ActiveRecord
32
37
 
33
38
  def valid_strategy?
34
39
  if !strategies.include?(strategy.to_sym)
35
- logger.info "Unknown role strategy #{strategy}"
40
+ logger.info "Unknown role strategy #{strategy}" if logging?
36
41
  raise ArgumentError, "Unknown role strategy #{strategy}"
37
42
  end
38
43
  end
@@ -46,7 +51,7 @@ module ActiveRecord
46
51
  end
47
52
 
48
53
  def run_migration
49
- logger.debug "Create migration for role_strategy: #{strategy}"
54
+ logger.debug "Create migration for role_strategy: #{strategy}" if logging?
50
55
  migration_name = "add_#{strategy}_strategy"
51
56
  target_migration_name = reverse? ? reverse_migration_name(migration_name) : migration_name
52
57
  migration_template "#{migration_name}.erb", "db/migrate/#{target_migration_name}"
@@ -54,12 +59,14 @@ module ActiveRecord
54
59
  reverse_migration!(generated_migration) if generated_migration && reverse?
55
60
  end
56
61
 
57
- include Rails3::Assist::BasicLogger
58
-
59
62
  def logfile
60
63
  options[:logfile]
61
64
  end
62
65
 
66
+ def logging?
67
+ options[:logging]
68
+ end
69
+
63
70
  def strategies
64
71
  [:admin_flag, :role_string, :one_role, :many_roles, :roles_mask]
65
72
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_active_record}
8
- s.version = "0.4.7"
8
+ s.version = "0.4.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2011-03-04}
11
+ s.authors = [%q{Kristian Mandrup}]
12
+ s.date = %q{2011-05-08}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in Active Record}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -91,8 +91,8 @@ Gem::Specification.new do |s|
91
91
  "spec/spec_helper.rb"
92
92
  ]
93
93
  s.homepage = %q{http://github.com/kristianmandrup/roles_active_record}
94
- s.require_paths = ["lib"]
95
- s.rubygems_version = %q{1.6.1}
94
+ s.require_paths = [%q{lib}]
95
+ s.rubygems_version = %q{1.8.0}
96
96
  s.summary = %q{Implementation of Roles generic API for Active Record}
97
97
  s.test_files = [
98
98
  "spec/fixtures/many_roles_setup.rb",
@@ -136,6 +136,7 @@ Gem::Specification.new do |s|
136
136
  s.add_development_dependency(%q<database_cleaner>, [">= 0.6"])
137
137
  s.add_development_dependency(%q<rspec>, [">= 2.4.1"])
138
138
  s.add_development_dependency(%q<generator-spec>, [">= 0.7.3"])
139
+ s.add_development_dependency(%q<migration_assist>, ["~> 0.2.0"])
139
140
  s.add_runtime_dependency(%q<roles_generic>, [">= 0.3.8"])
140
141
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
141
142
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.4.0"])
@@ -144,6 +145,7 @@ Gem::Specification.new do |s|
144
145
  s.add_dependency(%q<database_cleaner>, [">= 0.6"])
145
146
  s.add_dependency(%q<rspec>, [">= 2.4.1"])
146
147
  s.add_dependency(%q<generator-spec>, [">= 0.7.3"])
148
+ s.add_dependency(%q<migration_assist>, ["~> 0.2.0"])
147
149
  s.add_dependency(%q<roles_generic>, [">= 0.3.8"])
148
150
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
149
151
  s.add_dependency(%q<sugar-high>, ["~> 0.4.0"])
@@ -153,6 +155,7 @@ Gem::Specification.new do |s|
153
155
  s.add_dependency(%q<database_cleaner>, [">= 0.6"])
154
156
  s.add_dependency(%q<rspec>, [">= 2.4.1"])
155
157
  s.add_dependency(%q<generator-spec>, [">= 0.7.3"])
158
+ s.add_dependency(%q<migration_assist>, ["~> 0.2.0"])
156
159
  s.add_dependency(%q<roles_generic>, [">= 0.3.8"])
157
160
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
158
161
  s.add_dependency(%q<sugar-high>, ["~> 0.4.0"])
@@ -1,6 +1,6 @@
1
1
  require 'rspec'
2
2
  require 'rspec/autorun'
3
- require 'rails3_artifactor'
3
+ require 'rails_artifactor'
4
4
  require 'generator-spec'
5
5
  require 'roles_generic'
6
6
 
@@ -5,7 +5,7 @@ require 'generators/active_record/roles/roles_generator'
5
5
 
6
6
  # root_dir = Rails3::Assist::Directory.rails_root
7
7
  # root_dir = File.join(Rails.application.config.root_dir, 'rails')
8
- root_dir = Rails.root
8
+ root_dir = Rails.root.to_s
9
9
 
10
10
  describe 'roles generator' do
11
11
  describe 'ORM: active_record' do
@@ -2,11 +2,12 @@ require 'migration_spec_helper'
2
2
 
3
3
  require_generator :active_record => :roles_migration
4
4
 
5
- root_dir = Rails::Migration::Assist.rails_root_dir
6
- Rails3::Assist::Directory.rails_root = root_dir
7
- Rails::Migration::Assist.orm = :active_record
8
-
9
- puts "root_dir: #{root_dir}"
5
+ # root_dir = Rails::Migration::Assist.rails_root_dir
6
+ # RailsAssist::Directory.rails_root = root_dir
7
+ #
8
+ # Rails::Migration::Assist.orm = :active_record
9
+ #
10
+ # puts "root_dir: #{root_dir}"
10
11
 
11
12
  describe 'roles_migration_generator' do
12
13
  use_orm :active_record
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roles_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-04 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2011-05-08 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: database_cleaner
17
- requirement: &2156732560 !ruby/object:Gem::Requirement
16
+ requirement: &2156655440 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0.6'
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *2156732560
24
+ version_requirements: *2156655440
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rspec
28
- requirement: &2156732080 !ruby/object:Gem::Requirement
27
+ requirement: &2156654800 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 2.4.1
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2156732080
35
+ version_requirements: *2156654800
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: generator-spec
39
- requirement: &2156731600 !ruby/object:Gem::Requirement
38
+ requirement: &2156654120 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,21 @@ dependencies:
44
43
  version: 0.7.3
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2156731600
46
+ version_requirements: *2156654120
47
+ - !ruby/object:Gem::Dependency
48
+ name: migration_assist
49
+ requirement: &2156653540 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2156653540
48
58
  - !ruby/object:Gem::Dependency
49
59
  name: roles_generic
50
- requirement: &2156731060 !ruby/object:Gem::Requirement
60
+ requirement: &2156652700 !ruby/object:Gem::Requirement
51
61
  none: false
52
62
  requirements:
53
63
  - - ! '>='
@@ -55,10 +65,10 @@ dependencies:
55
65
  version: 0.3.8
56
66
  type: :runtime
57
67
  prerelease: false
58
- version_requirements: *2156731060
68
+ version_requirements: *2156652700
59
69
  - !ruby/object:Gem::Dependency
60
70
  name: require_all
61
- requirement: &2156730500 !ruby/object:Gem::Requirement
71
+ requirement: &2156652100 !ruby/object:Gem::Requirement
62
72
  none: false
63
73
  requirements:
64
74
  - - ~>
@@ -66,10 +76,10 @@ dependencies:
66
76
  version: 1.2.0
67
77
  type: :runtime
68
78
  prerelease: false
69
- version_requirements: *2156730500
79
+ version_requirements: *2156652100
70
80
  - !ruby/object:Gem::Dependency
71
81
  name: sugar-high
72
- requirement: &2156730000 !ruby/object:Gem::Requirement
82
+ requirement: &2156651460 !ruby/object:Gem::Requirement
73
83
  none: false
74
84
  requirements:
75
85
  - - ~>
@@ -77,10 +87,10 @@ dependencies:
77
87
  version: 0.4.0
78
88
  type: :runtime
79
89
  prerelease: false
80
- version_requirements: *2156730000
90
+ version_requirements: *2156651460
81
91
  - !ruby/object:Gem::Dependency
82
92
  name: meta_where
83
- requirement: &2156729440 !ruby/object:Gem::Requirement
93
+ requirement: &2156650660 !ruby/object:Gem::Requirement
84
94
  none: false
85
95
  requirements:
86
96
  - - ! '>='
@@ -88,7 +98,7 @@ dependencies:
88
98
  version: 1.0.1
89
99
  type: :runtime
90
100
  prerelease: false
91
- version_requirements: *2156729440
101
+ version_requirements: *2156650660
92
102
  description: Makes it easy to set a role strategy on your User model in Active Record
93
103
  email: kmandrup@gmail.com
94
104
  executables: []
@@ -169,7 +179,6 @@ files:
169
179
  - spec/roles_active_record/strategy/single/role_string_spec.rb
170
180
  - spec/roles_active_record/strategy/user_setup.rb
171
181
  - spec/spec_helper.rb
172
- has_rdoc: true
173
182
  homepage: http://github.com/kristianmandrup/roles_active_record
174
183
  licenses: []
175
184
  post_install_message:
@@ -190,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
199
  version: '0'
191
200
  requirements: []
192
201
  rubyforge_project:
193
- rubygems_version: 1.6.1
202
+ rubygems_version: 1.8.0
194
203
  signing_key:
195
204
  specification_version: 3
196
205
  summary: Implementation of Roles generic API for Active Record