Sha256: 6405acf580de42257700cc4c71b4ff70e71031231b190dd83b844783c42324f6

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

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 build_value(new_value, previous_value)
        if previous_value.is_a?(::Array)
          previous_value + [new_value]
        else
          new_value
        end
      end

      def default_value
        repeat? ? [] : nil
      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

25 entries across 25 versions & 3 rubygems

Version Path
eac_cli-0.18.0 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.100.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.21.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.99.1 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.17.0 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.99.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.98.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.97.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.96.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.16.3 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.95.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.16.2 lib/eac_cli/definition/positional_argument.rb
eac_cli-0.16.1 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.94.3 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.16.0 lib/eac_cli/definition/positional_argument.rb
avm-tools-0.94.2 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
avm-tools-0.94.1 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.15.1 lib/eac_cli/definition/positional_argument.rb
eac_cli-0.15.0 lib/eac_cli/definition/positional_argument.rb
ehbrs-tools-0.20.0 vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb