Sha256: 1148e47a7b408dd261c908e4b455dbf2337db1b3fb03c784388f95d7e7e8f849

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

class RakeCommander
  module Options
    module Error
      # Relates to the `required` parameter when defining an option.
      class MissingOption < RakeCommander::Options::Error::Base
        def initialize(value = nil, from: nil)
          super("missing required option: #{to_message(value)}", from: from)
        end

        def options
          super | to_options(@value)
        end

        protected

        def to_message(value)
          case value
          when RakeCommander::Option
            "#{value.name_hyphen} (#{value.short_hyphen})"
          when Hash
            to_message(value.values.uniq)
          when Array
            value.map do |v|
              v.is_a?(RakeCommander::Option)? to_message(v) : v
            end.join(', ')
          else
            super
          end
        end

        private

        def to_options(value)
          case value
          when RakeCommander::Option
            [value]
          when Array
            value.select {|v| v.is_a?(RakeCommander::Option)}
          when Hash
            to_options(value.values)
          else
            []
          end.compact
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rake-commander-0.4.0 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.3.6 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.3.5 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.3.3 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.12 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.11 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.10 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.7 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.6 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.5 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.4 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.3 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.2 lib/rake-commander/options/error/missing_option.rb
rake-commander-0.2.0 lib/rake-commander/options/error/missing_option.rb