Sha256: 363b838c7c8d0f8e7a06faabec18f3232bbb5056f4beb7847e21b5dffba5d788

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

class EcoRake
  class Option
    module Mirror
      # It allows to redirect options
      # @param value [String, Symbol] the value to use.
      # @return [String] command option with value
      def mirror(value = :not_used, raise: false)
        opt = name_hyphened
        return boolean_mirror(value) unless argument?

        missing = (value == :not_used) && !default?
        msg     = "required argument value #{argument} for option #{name} (#{short})"
        raise ArgumentError, msg if missing && argument_required? && raise
        return nil               if missing && argument_required?

        value = value == :not_used ? default : value
        "#{opt} \"#{value}\""
      end

      private

      # Implements the mirror of Boolean options/switches.
      def boolean_mirror(value = :not_used)
        opt = name_hyphened
        puts "boolean_mirror (#{value}): #{opt}" if name == :no_get

        return nil unless [TrueClass, NilClass, FalseClass].any? {|klass| type_coercion == klass}
        enabled_value = !boolean_name? || [TrueClass, NilClass].any? {|klass| type_coercion == klass}
        return opt              if value == enabled_value
        return name_false_hypen if boolean_name? && value == !enabled_value
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eco-rake-0.1.6 lib/eco-rake/option/mirror.rb
eco-rake-0.1.5 lib/eco-rake/option/mirror.rb
eco-rake-0.1.4 lib/eco-rake/option/mirror.rb
eco-rake-0.1.3 lib/eco-rake/option/mirror.rb
eco-rake-0.1.2 lib/eco-rake/option/mirror.rb
eco-rake-0.1.1 lib/eco-rake/option/mirror.rb