21
22
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
54
55
56
57
58
|
# File 'lib/generators/mongoid/roles/roles_generator.rb', line 21
def apply_role_strategy
if logfile?
require 'logging_assist'
class_eval do
send :include, RailsAssist::BasicLogger
end
logger.add_logfile :logfile => logfile if logfile
debug "apply_role_strategy for : #{strategy} in model #{user_file}"
end
if !valid_strategy?
error "Strategy #{strategy} is not currently supported, please try one of #{valid_strategies.join(', ')}"
end
if !has_model_file?(user_file)
error "User model #{user_file} not found"
return
end
if !is_mongoid_model?(user_file)
error "User model #{user_file} is not a Mongoid Document"
return
end
begin
debug "Trying to insert roles code into #{user_file}"
insert_into_model user_file, :after => /include Mongoid::\w+/ do
insertion_text
end
rescue Exception => e
error "Error: #{e.message}" if logger
end
copy_role_class if role_class_strategy?
end
|