class AuthThree::Generators::InstallGenerator
Public Instance Methods
copy_application_controller()
click to toggle source
# 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()
click to toggle source
# File lib/generators/install_generator.rb, line 73 def further_instructions readme "README.md" end
generate_db_content()
click to toggle source
# File lib/generators/install_generator.rb, line 9 def generate_db_content invoke "active_record:model", ['user'], migration: true end
generate_routes()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/generators/install_generator.rb, line 23 def migrate_users_data rake "db:migrate" end
Private Instance Methods
controller_source(controller_name)
click to toggle source
# File lib/generators/install_generator.rb, line 86 def controller_source(controller_name) if options[:namespace] File.expand_path("../../templates/json_controllers/#{controller_name}", __FILE__) else File.expand_path("../../templates/html_controllers/#{controller_name}", __FILE__) end end
controllers_path()
click to toggle source
# File lib/generators/install_generator.rb, line 78 def controllers_path if options[:namespace] File.join("app", "controllers", "#{options[:namespace]}") else File.join("app", "controllers") end end
create_users_migration_file()
click to toggle source
# File lib/generators/install_generator.rb, line 98 def create_users_migration_file Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_create_users.rb$/).first end
migration_path()
click to toggle source
# File lib/generators/install_generator.rb, line 94 def migration_path @migration_path ||= File.join("db", "migrate") end
model_path()
click to toggle source
# File lib/generators/install_generator.rb, line 102 def model_path @model_path ||= File.join("app", "models") end