Class: Tennpipes::Generators::Project
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Tennpipes::Generators::Project
- Includes:
- Actions, Components::Actions, Runner, Thor::Actions
- Defined in:
- lib/tennpipes-init/generators/project.rb
Overview
Responsible for generating new Tennpipes projects based on the specified project components.
Class Method Summary collapse
Instance Method Summary collapse
-
#bundle_dependencies ⇒ Object
Bundle all required components using bundler and Gemfile.
-
#finish_message ⇒ Object
Finish message.
-
#git_author_email ⇒ Object
Returns the git author email config or a fill-in value.
-
#git_author_name ⇒ Object
Returns the git author name config or a fill-in value.
-
#setup_components ⇒ Object
For each component, retrieve a valid choice and then execute the associated generator.
-
#setup_project ⇒ Object
Copies over the Tennpipes base application app.
-
#setup_test_files ⇒ Object
Generates test files for tiny app skeleton.
Methods included from 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 Runner
#app, #generate, #git, #project, #rake
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/project.rb', line 13 def self.; "tennpipes-init project [name] [options]"; end |
.source_root ⇒ Object
12 |
# File 'lib/tennpipes-init/generators/project.rb', line 12 def self.source_root; File.(File.dirname(__FILE__)); end |
Instance Method Details
#bundle_dependencies ⇒ Object
Bundle all required components using bundler and Gemfile.
123 124 125 126 127 |
# File 'lib/tennpipes-init/generators/project.rb', line 123 def bundle_dependencies if [:bundle] run_bundler end end |
#finish_message ⇒ Object
Finish message.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/tennpipes-init/generators/project.rb', line 132 def say say '=' * 65, :green say "#{name} is ready for development!", :green say '=' * 65, :green say "$ cd #{[:root]}/#{name}" say "$ bundle" unless [:bundle] say "=" * 65, :green say end |
#git_author_email ⇒ Object
Returns the git author email config or a fill-in value.
154 155 156 157 |
# File 'lib/tennpipes-init/generators/project.rb', line 154 def = `git config user.email`.chomp rescue '' .empty? ? "TODO: Write your email address" : end |
#git_author_name ⇒ Object
Returns the git author name config or a fill-in value.
146 147 148 149 |
# File 'lib/tennpipes-init/generators/project.rb', line 146 def = `git config user.name`.chomp rescue '' .empty? ? "TODO: Write your name" : end |
#setup_components ⇒ Object
For each component, retrieve a valid choice and then execute the associated generator.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tennpipes-init/generators/project.rb', line 82 def setup_components return if [:template] @_components = .dup.slice(*self.class.component_types) self.class.component_types.each do |comp| choice = @_components[comp] = resolve_valid_choice(comp) execute_component_setup(comp, choice) end store_component_config('.components') store_component_choice(:namespace, @project_name) store_component_choice(:migration_format, [:migration_format]) end |
#setup_project ⇒ Object
Copies over the Tennpipes base application app.
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 75 76 77 |
# File 'lib/tennpipes-init/generators/project.rb', line 44 def setup_project valid_constant? name app = ([:app] || "App") @project_name = name.gsub(/\W/, '_').underscore.camelize @app_name = app.gsub(/\W/, '_').camelize self.destination_root = File.join([:root], name) if [:template] execute_runner(:template, [:template]) else directory('project/', destination_root) empty_directory destination_root('public/images') empty_directory destination_root('public/javascripts') empty_directory destination_root('public/stylesheets') store_component_config('.components') unless [:lean] app_skeleton('app', [:tiny]) append_file destination_root('config/apps.rb'), "Tennpipes.mount('#{@project_name}::#{@app_name}', :app_file => Tennpipes.root('app/app.rb')).to('/')\n" end template 'templates/Gemfile.tt', destination_root('Gemfile') template 'templates/Rakefile.tt', destination_root('Rakefile') template 'templates/project_bin.tt', destination_root("bin/#{name}") File.chmod(0755, destination_root("bin/#{name}")) if .gem? template 'templates/gem/gemspec.tt', destination_root(name + '.gemspec') template 'templates/gem/README.md.tt', destination_root('README.md') template 'templates/gem/lib/libname.tt', destination_root("lib/#{name}.rb") template 'templates/gem/lib/libname/version.tt', destination_root("lib/#{name}/version.rb") else empty_directory_with_keep_file destination_root('tmp') empty_directory_with_keep_file destination_root('log') end end end |
#setup_test_files ⇒ Object
Generates test files for tiny app skeleton.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/tennpipes-init/generators/project.rb', line 97 def setup_test_files if [:tiny] && @_components[:test] != :none test_component = @_components[:test] test_component = "rspec" if test_component == "cucumber" uppercase_test_component = test_component.upcase controller_template_name = "#{uppercase_test_component}_CONTROLLER_TEST" helper_template_name = "#{uppercase_test_component}_HELPER_TEST" return unless defined?(controller_template_name) controller_content = instance_eval(controller_template_name).gsub(/!PATH!/, "Controller").gsub(/!NAME!/, "").gsub(/!EXPANDED_PATH!/, "/") helper_content = instance_eval(helper_template_name).gsub(/!NAME!/, "#{@project_name}::#{@app_name}::#{DEFAULT_HELPER_NAME}") proc{|*args| args.map{|str| str.gsub!(/!PATH!/, recognize_path)} }.call(controller_content, helper_content) directory_name = [:rspec, :steak].include?(test_component.to_sym) ? "spec" : "test" base_path = File.join(directory_name, "app") create_file destination_root("#{base_path}/controllers/controllers_#{directory_name}.rb"), controller_content, :skip => true create_file destination_root("#{base_path}/helpers/helpers_#{directory_name}.rb"), helper_content, :skip => true helper_path = destination_root(File.join(directory_name, "#{directory_name == "spec" ? "spec_helper" : "test_config"}.rb")) gsub_file helper_path, %r{helpers/\*\*/\*\.rb}, "helpers.rb" end end |