Sha256: 83f21834837923319c675c980674eb3f6ac2e77899f99f47cbfbb1d7dbe18e72

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "rails/generators"

module Runger
  module Generators
    class ConfigGenerator < ::Rails::Generators::NamedBase
      source_root File.expand_path("templates", __dir__)

      class_option :yml, type: :boolean
      class_option :app, type: :boolean, default: false
      argument :parameters, type: :array, default: [], banner: "param1 param2"

      # check_class_collision suffix: "Config"

      def run_install_if_needed
        return if ::Rails.root.join(static_config_root, "application_config.rb").exist?
        generate "runger:install"
      end

      def create_config
        template "config.rb", File.join(config_root, class_path, "#{file_name}_config.rb")
      end

      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

      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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
runger_config-4.0.0 lib/generators/runger/config/config_generator.rb