Class: Plumbum::ManyProvider

Inherits:
Object
  • Object
show all
Includes:
Providers::Plural
Defined in:
lib/plumbum/many_provider.rb

Overview

Provider that provides a mapping of keys to values.

Instance Method Summary collapse

Methods included from Provider

#get, #has?, #options, #read_only?, #set, #write_once?

Constructor Details

#initialize(values: Plumbum::UNDEFINED, **options) ⇒ ManyProvider

Returns a new instance of ManyProvider.

Parameters:

  • values (Hash{String, Symbol => Object}) (defaults to: Plumbum::UNDEFINED)

    the provided values.

  • options (Hash)

    additional options for the provider.



13
14
15
16
17
18
# File 'lib/plumbum/many_provider.rb', line 13

def initialize(values: Plumbum::UNDEFINED, **options)
  super()

  @values  = normalize_values(values)
  @options = validate_options(options)
end

Instance Method Details

#valuesHash

Returns the key-value pairs returned by the provider.

Returns:

  • (Hash)

    the key-value pairs returned by the provider.



21
22
23
# File 'lib/plumbum/many_provider.rb', line 21

def values
  @values == Plumbum::UNDEFINED ? {} : super.dup
end

#values=(values) ⇒ Object

Parameters:

  • values (Hash{String, Symbol => Object})

    the updated values.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/plumbum/many_provider.rb', line 26

def values=(values)
  validate_values(values)

  values = values.transform_keys(&:to_s)

  changed_values = find_changed_values(values)

  changed_values.each_key { |key| require_mutable(key) }

  @values = self.values.merge(changed_values)
end