Sha256: 7b6584e75bc60ca737ce4c119f3d7b32a7a87d2224e184f35c200dc37a871cda

Contents?: true

Size: 880 Bytes

Versions: 138

Compression:

Stored size: 880 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  class Parser
    require_sub __FILE__
    enable_simple_cache
    common_constructor :definition, :argv

    private

    def parsed_uncached
      raise 'Definition has no alternatives' if alternatives.empty?
      raise first_error unless alternatives.select(&:success?).any?

      alternatives_parsed(true).merge(alternatives_parsed(false))
    end

    def alternatives_parsed(error)
      alternatives.select { |a| error == a.error? }.map(&:parsed).reverse
        .inject(::EacRubyUtils::Struct.new) { |a, e| a.merge(e) }
    end

    def alternatives_uncached
      definition.alternatives
        .map { |alternative| ::EacCli::Parser::Alternative.new(alternative, argv) }
    end

    def first_error_uncached
      alternatives.lazy.select(&:error?).map(&:error).first
    end
  end
end

Version data entries

138 entries across 138 versions & 3 rubygems

Version Path
eac_cli-0.34.0 lib/eac_cli/parser.rb
eac_tools-0.66.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.65.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.65.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.33.0 lib/eac_cli/parser.rb
eac_tools-0.64.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.32.0 lib/eac_cli/parser.rb
eac_tools-0.63.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.62.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.31.0 lib/eac_cli/parser.rb
eac_tools-0.62.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.61.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.61.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.60.3 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.60.2 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.60.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.60.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.59.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.58.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.57.0 sub/eac_cli/lib/eac_cli/parser.rb