class Archangel::Generators::DummyGenerator

Archangel dummy application generator for testing

Constants

PASSTHROUGH_OPTIONS

Rails flags available to be passed with generator

Attributes

database[R]

Database type

lib_name[R]

Library name

Public Instance Methods

clean_up() click to toggle source

Remove dummy directory

# File lib/generators/archangel/dummy/dummy_generator.rb, line 55
def clean_up
  remove_directory_if_exists(dummy_path)
end
copy_dummy_config() click to toggle source

Copy dummy application files

# File lib/generators/archangel/dummy/dummy_generator.rb, line 77
def copy_dummy_config
  @lib_name = options[:lib_name]
  @database = options[:database]

  %w[config/database.yml].each do |tpl|
    template tpl, "#{dummy_path}/#{tpl}", force: true
  end
end
dummy_cleanup() click to toggle source

Remove unnecessary generated files

# 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() click to toggle source

Generate new dummy directory

# File lib/generators/archangel/dummy/dummy_generator.rb, line 62
def generate_dummy
  opts = option_defaults.merge(options)
                        .slice(*PASSTHROUGH_OPTIONS)
                        .merge(option_constants)

  puts "Generating dummy Rails application..."

  invoke Rails::Generators::AppGenerator,
         [File.expand_path(dummy_path, destination_root)],
         opts
end
prevent_application_dummy() click to toggle source

Do not allowing running the generator within the application

# 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() click to toggle source

Insert config options in test environment

# 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

Protected Instance Methods

dummy_database() click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 140
def dummy_database
  ENV["DB"] || "sqlite3"
end
dummy_path() click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 144
def dummy_path
  ENV["DUMMY_PATH"] || "spec/dummy"
end
inject_require_for(requirement) click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 124
        def inject_require_for(requirement)
          insert_into_file("config/application.rb",
                           before: /require "#{@lib_name}"/,
                           verbose: true) do
            <<-APP_CONFIG.strip_heredoc.indent(2)

              begin
                require "#{requirement}"
              rescue LoadError
                # #{requirement} is not available.
              end

            APP_CONFIG
          end
        end
option_constants() click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 160
def option_constants
  {
    force: true,
    skip_bundle: true,
    skip_git: true,
    old_style_hash: false
  }
end
option_defaults() click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 150
def option_defaults
  {
    database: dummy_database,
    skip_turbolinks: true,
    skip_bootsnap: true,
    skip_action_cable: true,
    skip_active_storage: true
  }
end
remove_directory_if_exists(path) click to toggle source
# File lib/generators/archangel/dummy/dummy_generator.rb, line 120
def remove_directory_if_exists(path)
  remove_dir(path) if File.directory?(path)
end