lib/generators/runger/config/config_generator.rb in runger_config-4.0.0 vs lib/generators/runger/config/config_generator.rb in runger_config-5.0.0

- old
+ new

@@ -1,46 +1,49 @@ # frozen_string_literal: true -require "rails/generators" +require 'rails/generators' -module Runger - module Generators - class ConfigGenerator < ::Rails::Generators::NamedBase - source_root File.expand_path("templates", __dir__) +module Runger::Generators ; end - class_option :yml, type: :boolean - class_option :app, type: :boolean, default: false - argument :parameters, type: :array, default: [], banner: "param1 param2" +class Runger::Generators::ConfigGenerator < Rails::Generators::NamedBase + source_root File.expand_path('templates', __dir__) - # check_class_collision suffix: "Config" + class_option :yml, type: :boolean + class_option :app, type: :boolean, default: false + argument :parameters, type: :array, default: [], banner: 'param1 param2' - def run_install_if_needed - return if ::Rails.root.join(static_config_root, "application_config.rb").exist? - generate "runger:install" - end + # check_class_collision suffix: "Config" - def create_config - template "config.rb", File.join(config_root, class_path, "#{file_name}_config.rb") - end + def run_install_if_needed + return if ::Rails.root.join(static_config_root, 'application_config.rb').exist? - def create_yml - create_yml = options.fetch(:yml) { yes?("Would you like to generate a #{file_name}.yml file?") } - return unless create_yml - template "config.yml", File.join("config", "#{file_name}.yml") - end + generate('runger:install') + end - private + def create_config + template('config.rb', File.join(config_root, class_path, "#{file_name}_config.rb")) + end - def static_config_root - Runger::Settings.autoload_static_config_path || Runger::DEFAULT_CONFIGS_PATH - end + def create_yml + create_yml = + options.fetch(:yml) { + yes?("Would you like to generate a #{file_name}.yml file?") + } + return unless create_yml - def config_root - if options[:app] - "app/configs" - else - static_config_root - end - end + template('config.yml', File.join('config', "#{file_name}.yml")) + end + + private + + def static_config_root + Runger::Settings.autoload_static_config_path || Runger::DEFAULT_CONFIGS_PATH + end + + def config_root + if options[:app] + 'app/configs' + else + static_config_root end end end