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_tools-0.76.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.37.0 lib/eac_cli/parser.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.36.0 lib/eac_cli/parser.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.72.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.70.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.70.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.69.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.69.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.35.1 lib/eac_cli/parser.rb
eac_cli-0.34.1 lib/eac_cli/parser.rb
eac_tools-0.68.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.67.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.35.0 lib/eac_cli/parser.rb
eac_tools-0.67.0 sub/eac_cli/lib/eac_cli/parser.rb