Class: ApiSampler::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/api_sampler/install/install_generator.rb

Overview

Create an initializer with description of configuration and defaults. Mount api_sampler at MOUNT_PATH (specified with --mount-at option, defaults to /api_sampler). Copy and run migrations unless --no-migrate flag is given.

Run the following command for more details:

 $ rails generate api_sampler:install --help

Instance Method Summary collapse

Instance Method Details

#create_initializervoid

This method returns an undefined value.

Create an initializer with description of configuration and defaults.


25
26
27
# File 'lib/generators/api_sampler/install/install_generator.rb', line 25

def create_initializer
  template 'api_sampler.rb', 'config/initializers/api_sampler.rb'
end

#display_notesvoid

This method returns an undefined value.

Display notes after installation.


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/generators/api_sampler/install/install_generator.rb', line 46

def display_notes           # rubocop:disable Metrics/MethodLength
  log <<-NOTES.strip_heredoc

    Congratulations! api_sampler is now installed. What to do next?

    - Change the default mount point of api_sampler at `config/routes.rb'.
    - Inspect and edit the default config at `config/initializers/api_sampler.rb'.
  NOTES

  log <<-NOTES.strip_heredoc unless options.migrate?
    - Copy and run api_sampler migrations by executing the following commands:

        $ bundle exec rails api_sampler:install:migrations
        $ bundle exec rails db:migrate SCOPE=api_sampler
  NOTES

  log <<-NOTES.strip_heredoc

    Note: you can always undo api_sampler migrations by running this command:

        $ bundle exec rails db:migrate SCOPE=api_sampler VERSION=0
  NOTES
end

#migratevoid

This method returns an undefined value.

Copy and run migrations unless --no-migrate flag is given.


37
38
39
40
41
42
# File 'lib/generators/api_sampler/install/install_generator.rb', line 37

def migrate
  return unless options.migrate?

  rake 'api_sampler:install:migrations'
  rake 'db:migrate SCOPE=api_sampler'
end

#mount_enginevoid

This method returns an undefined value.

Mount Engine to --mount-at.


31
32
33
# File 'lib/generators/api_sampler/install/install_generator.rb', line 31

def mount_engine
  route "mount ApiSampler::Engine, at: #{options.mount_at.inspect}"
end