Class: Tennpipes::Generators::Controller
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Tennpipes::Generators::Controller
- Includes:
- Actions, Tennpipes::Generators::Components::Actions, Thor::Actions
- Defined in:
- lib/tennpipes-init/generators/controller.rb
Overview
Responsible for generating route controllers and associated tests within a Tennpipes application.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_controller ⇒ Object
Execute controller generation.
Methods included from Tennpipes::Generators::Components::Actions
#controller_actions, #create_helper_files, #current_migration_number, #indent_spaces, #insert_mocking_include, #insert_test_suite_setup, #migration_exist?, #output_migration_file, #output_model_migration, #remove_migration, #return_last_migration_number
Methods included from Actions
#already_exists?, #app_skeleton, #apply_component_for, #apply_default_fields, #ask, #check_app_existence, #destination_root, #empty_directory_with_keep_file, #execute_component_setup, #fetch_app_name, #fetch_component_choice, #fetch_project_name, #in_app_root?, #include_component_module_for, included, #initializer, #inject_into_file, #insert_hook, #insert_into_gemfile, #insert_middleware, #invalid_fields, #keep_file, #middleware, #recognize_path, #require_contrib, #require_dependencies, #resolve_valid_choice, #retrieve_component_config, #run_bundler, #store_component_choice, #store_component_config, #test?, #tiny?, #valid_choice?, #valid_constant?
Class Method Details
.banner ⇒ Object
13 |
# File 'lib/tennpipes-init/generators/controller.rb', line 13 def self.; "tennpipes-init controller [name]"; end |
.source_root ⇒ Object
12 |
# File 'lib/tennpipes-init/generators/controller.rb', line 12 def self.source_root; File.(File.dirname(__FILE__)); end |
Instance Method Details
#create_controller ⇒ Object
Execute controller generation
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tennpipes-init/generators/controller.rb', line 38 def create_controller self.destination_root = [:root] if in_app_root? app = [:app] check_app_existence(app) @project_name = [:namespace].underscore.camelize @project_name = fetch_project_name(app) if @project_name.empty? @app_name = fetch_app_name(app) @actions = controller_actions(fields) @controller = name.to_s.underscore @layout = [:layout] if [:layout] && ![:layout].empty? block_opts = [] block_opts << ":parent => :#{[:parent]}" if [:parent] && ![:parent].empty? block_opts << ":provides => [#{[:provides]}]" if [:provides] && ![:provides].empty? @block_opts_string = block_opts.join(', ') unless block_opts.empty? self.behavior = :revoke if [:destroy] template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb") empty_directory destination_root(app, "/views/#{name.to_s.underscore}") if test? include_component_module_for(:test) path = @controller.dup if [:parent] && ![:parent].empty? path = Application.process_path_for_parent_params(path, [[:parent]]).prepend("/") end path.prepend("/") unless path.start_with?("/") generate_controller_test(name, path) end create_helper_files(app, name) unless [:'no-helper'] else say 'You are not at the root of a Tennpipes application! (config/boot.rb not found)' end end |