Class: Archangel::Generators::DummyGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Archangel::Generators::DummyGenerator
- Defined in:
- lib/generators/archangel/dummy/dummy_generator.rb
Overview
Archangel dummy application generator for testing
Constant Summary collapse
- PASSTHROUGH_OPTIONS =
Rails flags available to be passed with generator
%i[ database javascript pretend quiet skip_action_cable skip_active_record skip_active_storage skip_bootsnap skip_javascript skip_turbolinks ].freeze
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Database type.
-
#lib_name ⇒ Object
readonly
Library name.
Instance Method Summary collapse
-
#clean_up ⇒ Object
Remove dummy directory.
-
#copy_dummy_config ⇒ Object
Copy dummy application files.
-
#dummy_cleanup ⇒ Object
Remove unnecessary generated files.
-
#generate_dummy ⇒ Object
Generate new dummy directory.
-
#prevent_application_dummy ⇒ Object
Do not allowing running the generator within the application.
-
#test_default_url ⇒ Object
Insert config options in test environment.
Instance Attribute Details
#database ⇒ Object (readonly)
Database type
27 28 29 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 27 def database @database end |
#lib_name ⇒ Object (readonly)
Library name
32 33 34 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 32 def lib_name @lib_name end |
Instance Method Details
#clean_up ⇒ Object
Remove dummy directory
55 56 57 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 55 def clean_up remove_directory_if_exists(dummy_path) end |
#copy_dummy_config ⇒ Object
Copy dummy application files
77 78 79 80 81 82 83 84 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 77 def copy_dummy_config @lib_name = [:lib_name] @database = [:database] %w[config/database.yml].each do |tpl| template tpl, "#{dummy_path}/#{tpl}", force: true end end |
#dummy_cleanup ⇒ Object
Remove unnecessary generated files
108 109 110 111 112 113 114 115 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 108 def dummy_cleanup inside dummy_path do paths = %w[.gitignore db/seeds.rb Gemfile lib/tasks public/robots.txt spec test vendor] paths.each { |path| remove_file path } end end |
#generate_dummy ⇒ Object
Generate new dummy directory
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 62 def generate_dummy opts = option_defaults.merge() .slice(*PASSTHROUGH_OPTIONS) .merge(option_constants) puts "Generating dummy Rails application..." invoke Rails::Generators::AppGenerator, [File.(dummy_path, destination_root)], opts end |
#prevent_application_dummy ⇒ Object
Do not allowing running the generator within the application
46 47 48 49 50 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 46 def prevent_application_dummy return unless Rails.try(:root) && !Rails.root.blank? abort "Dummy generator cannot be run outside Archangel extension." end |
#test_default_url ⇒ Object
Insert config options in test environment
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/generators/archangel/dummy/dummy_generator.rb', line 89 def test_default_url insert_into_file("#{dummy_path}/config/environments/test.rb", after: "Rails.application.configure do") do <<-DEFAULT_URL.strip_heredoc.indent(2) config.action_mailer.default_url_options = { host: "localhost", port: 3000 } config.action_view.raise_on_missing_translations = true DEFAULT_URL end end |