Sha256: a4dec00d5effd7e305c5f0b7b307deb37fbf2e62ea1ae1615c75fe77cea5e02e

Contents?: true

Size: 1.44 KB

Versions: 41

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module RailsAppGenerator
  # Option for the rails generator
  #
  # This class maps closely (but not exactly) to Thor's options
  # The pattern is not exactly the same, it is easy to map the options
  # you need from other generators such as: railties/lib/rails/generators/app_base.rb
  #
  # @example
  # class_option    :skip_git, type: :boolean, default: false, desc: "Skip .gitignore file"
  # becomes
  # register_option :skip_git, type: :boolean, default: false, desc: "Skip .gitignore file"
  class BuildOption
    attr_reader :name, :desc, :type, :default, :required, :mapper

    def initialize(**args)
      @name = args[:name]
      @desc = args[:desc] || ''
      @type = args[:type] || :string
      @required = args.fetch(:required, false)
      @default = args[:default] || sane_default
      @mapper = args[:mapper] || sane_mapper

      raise ArgumentError, ':required should not be nil' if @required.nil?
    end

    def cmd_option(value); end

    private

    def sane_default
      case type
      when :string
        ''
      when :boolean
        false
      when :integer
        0
      when :array
        []
      when :hash
        {}
      end
    end

    def sane_mapper
      case type
      when :boolean
        RailsAppGenerator::MapOptionBooleanFlag.new
      when :string
        RailsAppGenerator::MapOptionString.new
      else
        RailsAppGenerator::MapOptionIgnore.new
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
rails_app_generator-0.1.28 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.27 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.26 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.25 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.24 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.23 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.22 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.21 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.20 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.19 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.18 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.17 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.16 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.15 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.14 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.13 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.12 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.11 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.10 lib/rails_app_generator/options/build_option.rb
rails_app_generator-0.1.9 lib/rails_app_generator/options/build_option.rb