Sha256: 644e1c2e3196299f9cff212b2a3ef0d9773fe844d5706c67477cd50500d4ae56

Contents?: true

Size: 582 Bytes

Versions: 5

Compression:

Stored size: 582 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/hash/indifferent_access'

module EacRubyUtils
  class OptionsConsumer
    def initialize(data)
      @data = data.with_indifferent_access
    end

    def consume(key, default_value = nil, &block)
      return default_value unless data.key?(key)

      value = data.delete(key)
      value = yield(value) if block
      value
    end

    def validate
      return if data.empty?

      raise "Invalid keys: #{data.keys}"
    end

    def left_data
      data.dup
    end

    private

    attr_reader :data
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eac_ruby_utils-0.10.1 lib/eac_ruby_utils/options_consumer.rb
eac_ruby_utils-0.10.0 lib/eac_ruby_utils/options_consumer.rb
eac_ruby_utils-0.9.0 lib/eac_ruby_utils/options_consumer.rb
eac_ruby_utils-0.8.0 lib/eac_ruby_utils/options_consumer.rb
eac_ruby_utils-0.7.0 lib/eac_ruby_utils/options_consumer.rb