Sha256: ca1c5c1996ddbd4da3448e113089a2a9dea7c4c506edb3c2e016a1151bb4998d

Contents?: true

Size: 969 Bytes

Versions: 35

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  class Definition
    class PositionalArgument
      DEFAULT_REQUIRED = true

      enable_listable
      lists.add_symbol :option, :optional, :repeat, :required, :subcommand
      common_constructor :name, :options, default: [{}] do
        options.assert_valid_keys(self.class.lists.option.values)
      end

      def identifier
        name.to_s.variableize.to_sym
      end

      def optional?
        !required?
      end

      def repeat?
        options[OPTION_REPEAT]
      end

      def required?
        return true if options.key?(OPTION_REQUIRED) && options.fetch(OPTION_REQUIRED)
        return false if options.key?(OPTION_OPTIONAL) && options.fetch(OPTION_OPTIONAL)

        DEFAULT_REQUIRED
      end

      def subcommand?
        options[OPTION_SUBCOMMAND]
      end

      def to_s
        "#{self.class.name.demodulize}[#{identifier}]"
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
avm-tools-0.91.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.90.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.89.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.88.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.12.6 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.87.1 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.19.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.18.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.12.5 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.87.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.17.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.86.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.85.1 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.85.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.16.5 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.84.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.83.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.12.4 lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.16.4 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.82.1 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb