Permalink
Browse files

fixed dependencies and made logging optional

  • Loading branch information...
1 parent 6baef8b commit c2349e9bbc6e97a6c98535d1ea41b80abe9dfa58 @kristianmandrup committed May 7, 2011
Showing with 23 additions and 15 deletions.
  1. +1 −0 Rakefile
  2. +21 −14 lib/generators/active_record/roles/roles_generator.rb
  3. +1 −1 spec/generator_spec_helper.rb
View
@@ -18,6 +18,7 @@ begin
gem.add_development_dependency 'database_cleaner', '>= 0.6'
gem.add_development_dependency "rspec", '>= 2.4.1'
gem.add_development_dependency "generator-spec", '>= 0.7.3'
+ gem.add_development_dependency 'migration_assist', '~> 0.2.0'
gem.add_dependency 'roles_generic', '>= 0.3.8'
gem.add_dependency 'require_all', '~> 1.2.0'
@@ -1,5 +1,4 @@
-require 'rails3_artifactor'
-require 'logging_assist'
+require 'rails_artifactor'
require 'generators/active_record/roles/core_ext'
module ActiveRecord
@@ -17,44 +16,52 @@ class RolesGenerator < Rails::Generators::NamedBase
class_option :user_role_class, :type => :string, :aliases => "-urc", :default => 'UserRole', :desc => "User Role join class"
class_option :default_roles, :type => :boolean, :aliases => "-dr", :default => true, :desc => "Use default roles :admin and :base"
- class_option :logfile, :type => :string, :aliases => "-l", :default => nil, :desc => "Logfile location"
+ class_option :logfile, :type => :string, :aliases => "-lf", :default => nil, :desc => "Logfile location"
+ class_option :logging, :type => :boolean, :aliases => "-l", :default => false, :desc => "Logging on?"
source_root File.dirname(__FILE__) + '/templates'
def apply_role_strategy
- logger.add_logfile :logfile => logfile if logfile
- logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
+ if logging?
+ require 'logging_assist'
+ self.class.send :include, Rails3::Assist::BasicLogger
+ logger.add_logfile :logfile => logfile if logfile
+ end
+
+ logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}" if logging?
if !valid_strategy?
- logger.error "Strategy '#{strategy}' is not valid, at least not for Active Record"
+ logger.error "Strategy '#{strategy}' is not valid, at least not for Active Record" if logging?
return
end
if !has_model? user_file
- logger.error "Could not apply roles strategy to #{user_class} model since the model file was not found"
+ logger.error "Could not apply roles strategy to #{user_class} model since the model file was not found" if logging?
return
end
begin
- logger.debug "Trying to insert roles code into #{user_class}"
+ logger.debug "Trying to insert roles code into #{user_class}" if logging?
insert_into_model user_file do
insertion_text
end
copy_role_models if roles_model_strategy?
rescue
# logger.debug "Error applying roles strategy to #{name}"
- logger.error "Error applying roles strategy to #{user_class}"
+ logger.error "Error applying roles strategy to #{user_class}" if logging?
end
end
protected
extend Rails3::Assist::UseMacro
- use_orm :active_record
-
- include Rails3::Assist::BasicLogger
+ use_orm :active_record
+
+ def logging?
+ options[:logging]
+ end
def user_file
user_class.as_filename
@@ -79,12 +86,12 @@ def copy_role_models
end
def copy_one_role_model
- logger.debug "generating role model for one_role strategy: #{role_file}"
+ logger.debug "generating role model for one_role strategy: #{role_file}" if logging?
template 'one_role/role.rb', "app/models/#{role_file}.rb"
end
def copy_many_roles_models
- logger.debug "generating role models for many_roles strategy: #{role_file} and #{user_file}"
+ logger.debug "generating role models for many_roles strategy: #{role_file} and #{user_file}" if logging?
template 'many_roles/role.rb', "app/models/#{role_file}.rb"
template 'many_roles/user_role.rb', "app/models/#{user_role_file}.rb"
@@ -1,6 +1,6 @@
require 'rspec'
require 'rspec/autorun'
-require 'rails3_artifactor'
+require 'rails_artifactor'
require 'generator-spec'
require 'roles_generic'

0 comments on commit c2349e9

Please sign in to comment.