class Gemsmith::Generators::Engine

Generates Ruby on Rails Engine support.

Public Instance Methods

run() click to toggle source

:reek: TooManyStatements

# File lib/gemsmith/generators/engine.rb, line 8
def run
  return unless runnable?

  install_rails
  create_engine
  create_generator_files
  stub_assets
  remove_files
end

Private Instance Methods

create_engine() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 30
def create_engine
  template "#{LIB_ROOT}/%gem_path%/engine.rb.tt"
  cli.run "rails plugin new --skip #{configuration.dig :gem, :name} #{engine_options}"
end
create_generator_files() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 35
def create_generator_files
  cli.empty_directory "#{generator_root}/templates"
  template "#{generator_root}/install/install_generator.rb.tt"
  template "#{generator_root}/install/USAGE.tt"
  template "#{generator_root}/upgrade/upgrade_generator.rb.tt"
  template "#{generator_root}/upgrade/USAGE.tt"
end
engine_options() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/gemsmith/generators/engine.rb, line 57
def engine_options
  "--skip-git " \
  "--skip-bundle " \
  "--skip-keeps " \
  "--skip-turbolinks " \
  "--skip-spring " \
  "--skip-test " \
  "--mountable " \
  "--dummy-path=spec/dummy"
end
generator_root() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 68
def generator_root
  "#{LIB_ROOT}/generators/%gem_path%"
end
indentation() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 72
def indentation
  "  " * (configuration.dig(:gem, :path).scan("/").size + 1)
end
install_rails() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 24
def install_rails
  return if cli.run "command -v rails > /dev/null"

  cli.run "gem install rails" if cli.yes? "Would you like to install Ruby on Rails (y/n)?"
end
remove_files() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/gemsmith/generators/engine.rb, line 49
def remove_files
  cli.remove_file "#{gem_name}/app/helpers/#{gem_path}/application_helper.rb", configuration
  cli.remove_file "#{gem_name}/lib/#{gem_path}/version.rb", configuration
  cli.remove_file "#{gem_name}/MIT-LICENSE", configuration
  cli.remove_file "#{gem_name}/README.rdoc", configuration
end
runnable?() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 20
def runnable?
  configuration.dig :generate, :engine
end
stub_assets() click to toggle source
# File lib/gemsmith/generators/engine.rb, line 43
def stub_assets
  cli.run %(printf "%s" > "#{gem_name}/app/assets/javascripts/#{gem_path}/application.js")
  cli.run %(printf "%s" > "#{gem_name}/app/assets/stylesheets/#{gem_path}/application.css")
end