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.81.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.38.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.37.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_cli-0.36.0 lib/eac_cli/definition/positional_argument.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.72.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.70.1 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb
eac_tools-0.70.0 sub/eac_cli/lib/eac_cli/definition/positional_argument.rb