Sha256: 5abb99ef568060602d568264669d313ea8de86d5a86d7e85297496a794728529

Contents?: true

Size: 1.39 KB

Versions: 88

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  class Config < ::SimpleDelegator
    class Entry
      class Options
        enable_simple_cache
        enable_listable

        lists.add_symbol :type, :undefined

        DEFAULT_VALUES = {
          before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
          required: true, store: true, type: TYPE_UNDEFINED, validator: nil
        }.freeze

        lists.add_symbol :option, *DEFAULT_VALUES.keys

        common_constructor :options do
          self.options = self.class.lists.option.hash_keys_validate!(options)
        end

        delegate :to_h, to: :options

        def [](key)
          values.fetch(key.to_sym)
        end

        def request_input_options
          values.slice(:bool, :list, :noecho)
        end

        DEFAULT_VALUES.each do |attr, default_value|
          define_method(attr.to_s + ([true, false].include?(default_value) ? '?' : '')) do
            self[attr]
          end
        end

        private

        def values_uncached
          consumer = options.to_options_consumer
          r = {}
          DEFAULT_VALUES.each do |key, default_value|
            value = consumer.consume(key)
            value = default_value if value.nil?
            r[key] = value
          end
          consumer.validate
          r
        end
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 3 rubygems

Version Path
eac_tools-0.45.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.44.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.43.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_cli-0.29.0 lib/eac_cli/config/entry/options.rb
eac_tools-0.42.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.41.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.40.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.39.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.38.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.37.2 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.37.1 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.37.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.36.1 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.36.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.35.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.34.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.33.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.32.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.31.1 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_tools-0.31.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb