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.35.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.34.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.33.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.32.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.31.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.31.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_cli-0.28.0 lib/eac_cli/parser.rb
eac_tools-0.30.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.29.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.28.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.27.2 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.27.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.27.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.26.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.25.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.25.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.24.1 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.24.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.23.0 sub/eac_cli/lib/eac_cli/parser.rb
eac_tools-0.22.0 sub/eac_cli/lib/eac_cli/parser.rb