Class: MongoMapper::Generators::RolesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Extended by:
Rails3::Assist::UseMacro
Includes:
Rails3::Assist::BasicLogger
Defined in:
lib/generators/mongo_mapper/roles/roles_generator.rb

Instance Method Summary collapse

Instance Method Details

#apply_role_strategyObject



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
53
# File 'lib/generators/mongo_mapper/roles/roles_generator.rb', line 23

def apply_role_strategy
  logger.add_logfile :logfile => logfile if logfile
  logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"

  if !valid_strategy?
    logger.error "Strategy '#{strategy}' is not valid. The valid strategies are: #{valid_strategies.join(', ')}"
    return
  end

  if !has_model_file?(user_file)
    logger.error "User model #{user_class} not found"
    return 
  end

  if !is_mongo_mapper_model?(user_file)
    logger.error "User model #{user_class} is not a Mongo Mapper Document"
    return 
  end
  
  begin 
    logger.debug "Trying to insert roles code into #{user_class}"     
             
    insert_into_model user_file, :after => /include MongoMapper::\w+/ do
      insertion_text
    end     
  rescue Exception => e
    logger.debug"Error: #{e.message}"
  end 
  
  copy_role_class if role_class_strategy?
end