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_cli-0.26.2 lib/eac_cli/config/entry/options.rb
avm-tools-0.114.0 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_cli-0.26.1 lib/eac_cli/config/entry/options.rb
eac_cli-0.26.0 lib/eac_cli/config/entry/options.rb
avm-tools-0.113.6 sub/eac_cli/lib/eac_cli/config/entry/options.rb
avm-tools-0.113.5 sub/eac_cli/lib/eac_cli/config/entry/options.rb
eac_cli-0.25.0 lib/eac_cli/config/entry/options.rb
avm-tools-0.113.4 sub/eac_cli/lib/eac_cli/config/entry/options.rb