Sha256: bf2d311c5a72b873a7d138ec286a5fb6ed73e1592f0087be1f193522565fcd1f

Contents?: true

Size: 1.34 KB

Versions: 205

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  class Definition
    class PositionalArgument
      DEFAULT_REQUIRED = true
      DEFAULT_VISIBLE = true

      enable_listable
      lists.add_symbol :option, :optional, :repeat, :required, :subcommand, :visible
      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

      def visible?
        options.key?(OPTION_VISIBLE) ? options.fetch(OPTION_VISIBLE) : DEFAULT_VISIBLE
      end
    end
  end
end

Version data entries

205 entries across 205 versions & 4 rubygems

Version Path
eac_tools-0.69.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.69.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.35.1 lib/eac_cli/definition/positional_argument.rb
eac_cli-0.34.1 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.68.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.67.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.35.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.67.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.34.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.66.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.65.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.65.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.33.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.64.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.32.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.63.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.62.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.31.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.62.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.61.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb