Class: DataMapper::Generators::RolesGenerator

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

Instance Method Summary collapse

Instance Method Details

#apply_role_strategyObject



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
54
55
56
# File 'lib/generators/data_mapper/roles/roles_generator.rb', line 26

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, at least not for Data Mapper"
     return 
   end

   if !has_model_file?(user_file)
     say "User model in #{user_file} not found", :red
     return 
   end
  
   if !is_data_mapper_model?(user_file)
     logger.error "User model in #{user_file} is not a Data Mapper resource"
     return 
   end
   
   begin 
     logger.debug "Trying to insert roles code into #{user_file}"     

     insert_into_model user_file, :after => 'include DataMapper::Resource'  do
       insertion_text
     end
   rescue Exeption => e
     logger.error "Error: #{e.message}"
   end 
   
   copy_role_models if role_class_strategy?        
end