Module: Clustr::Config

Defined in:
lib/clustr/config.rb,
lib/clustr/config/clusters.rb

Overview

Note:

This module should be accessed from within a static context.

Controls all configuration settings for the Clustr gem.

Defined Under Namespace

Classes: Clusters

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Mixed, Nil

Accesses Clustr::Config as an array of key-based values.

Examples:

Retrieve a singular key using a symbol

Clustr::Config[:a]

Retrieve a singular key using a string

Clustr::Config["a"]

Parameters:

  • key (Symbol)

    of the value to retrieve.

Returns:

  • (Mixed, Nil)

    Will return the value of the key or nil.



40
41
42
# File 'lib/clustr/config.rb', line 40

def self.[](key)
  @@_[key.to_sym]
end

.[]=(key, value) ⇒ Mixed

Sets or modifies a key and value within the current configuration state.

Examples:

Usage

Clustr::Config[:a] = "hello world!"

Parameters:

  • key (Symbol)

    of the value to set.

  • value (Mixed)

    of the element.

Returns:

  • (Mixed)

    the new value of the element.



52
53
54
# File 'lib/clustr/config.rb', line 52

def self.[]=(key,value)
  @@_[key.to_sym] = value
end

.delete!(*keys) ⇒ Hash

Removes a key from the current configuration state.

Examples:

Usage

Clustr::Config.delete!(:one, :or, :more, :keys)

Parameters:

  • keys (Symbol)

    of the values to delete.

Returns:

  • (Hash)

    the values that have been deleted



63
64
65
# File 'lib/clustr/config.rb', line 63

def self.delete!(*keys)
  keys.each { |k| @@_.delete(k.to_sym) }
end

.select(*args) ⇒ Hash

Note:

Keys not present within the configuration will be omitted from the returned hash.

Retrieves values for the provided keys.

Examples:

Guided Usage

Clustr::Config.select(:a, :b, :c, :d)

Parameters:

  • args (Splat)

    of the key value pairs to retrieve.

Returns:

  • (Hash)

    a hash of the keys present within configuration.



27
28
29
# File 'lib/clustr/config.rb', line 27

def self.select(*args)
  @@_.select { |key| args.include?(key) }
end