Class: AuthThree::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- AuthThree::Generators::InstallGenerator
show all
- Includes:
- ControllerHelpers, OrmHelpers
- Defined in:
- lib/generators/install_generator.rb
Instance Method Summary
collapse
#namespace_sessions_contents, #namespace_users_contents, #router_contents, #sessions_controller_contents, #users_controller_contents
Methods included from OrmHelpers
#migration_data, #migration_index_data, #model_contents
Instance Method Details
#copy_application_controller ⇒ Object
36
37
38
|
# File 'lib/generators/install_generator.rb', line 36
def copy_application_controller
copy_file(controller_source("application_controller.rb"), "#{File.join("app", "controllers")}/application_controller.rb", force: true)
end
|
#further_instructions ⇒ Object
73
74
75
|
# File 'lib/generators/install_generator.rb', line 73
def further_instructions
readme "README.md"
end
|
#generate_db_content ⇒ Object
9
10
11
|
# File 'lib/generators/install_generator.rb', line 9
def generate_db_content
invoke "active_record:model", ['user'], migration: true
end
|
#generate_routes ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/generators/install_generator.rb', line 59
def generate_routes
if options[:namespace]
content = router_contents(options[:namespace])
indent_depth = 0
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
route(content)
else
route "resources :users"
route "resource :session"
end
end
|
#generate_user_controllers ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/generators/install_generator.rb', line 40
def generate_user_controllers
controller_names = ['users', 'sessions']
controller_names.each do |name|
if options[:namespace]
generate "controller", "#{options[:namespace]}/#{name} --no-helper --no-assets"
content = send("namespace_#{name}_contents".to_sym, options[:namespace])
indent_depth = 0
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
inject_into_class("#{controllers_path}/#{name}_controller.rb", ("#{options[:namespace]}::".camelcase + "#{name}_controller".camelcase).constantize, content)
else
generate "controller", "#{name} --no-helper --no-assets"
content = send("#{name}_controller_contents".to_sym)
indent_depth = 0
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
inject_into_class("#{controllers_path}/#{name}_controller.rb", "#{name}_controller".camelcase.constantize, content)
end
end
end
|
#inject_create_users_migration_content ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/generators/install_generator.rb', line 13
def inject_create_users_migration_content
content = migration_data
indent_depth = 0
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
index_content = migration_index_data
require create_users_migration_file
insert_into_file(create_users_migration_file, content, after: ":users do |t|\n")
insert_into_file(create_users_migration_file, index_content, after: "t.timestamps\n end")
end
|
#inject_user_model_content ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/generators/install_generator.rb', line 27
def inject_user_model_content
content = model_contents
indent_depth = 0
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
inject_into_class("#{model_path}/user.rb", User, content)
end
|
#migrate_users_data ⇒ Object
23
24
25
|
# File 'lib/generators/install_generator.rb', line 23
def migrate_users_data
rake "db:migrate"
end
|