Module: Jafry::Configurator

Extended by:
Accessor
Defined in:
lib/jafry/configurator.rb

Overview

Module for saving and changing scheme’s configs

Since:

  • 0.2.0

Constant Summary collapse

@@schemes_configs =

Since:

  • 0.2.0

[]

Class Method Summary collapse

Methods included from Accessor

mattrs

Class Method Details

.defaultHash

Specifies default config

Returns:

  • (Hash)

    Default config

Since:

  • 0.2.0



59
60
61
# File 'lib/jafry/configurator.rb', line 59

def default
  {id_type: Jafry.id_type, id_wrapper: Jafry.id_wrapper}
end

.find_config(scheme_name) ⇒ Hash

Returns scheme by name

Parameters:

  • scheme_name (String)

    Scheme name

Returns:

  • (Hash)

    Hash of scheme name and config

Since:

  • 0.2.0



51
52
53
# File 'lib/jafry/configurator.rb', line 51

def find_config(scheme_name)
  self.schemes_configs.select {|item| item[:scheme] == scheme_name}.last
end

.get_config(scheme) ⇒ Hash

Finds config by scheme name

Parameters:

  • scheme (String)

    Scheme name

Returns:

  • (Hash)

    Config

Since:

  • 0.2.0



42
43
44
# File 'lib/jafry/configurator.rb', line 42

def get_config(scheme)
  find_config(scheme)[:config]
end

.init_or_update(scheme_name, config) ⇒ Object

Creates new or updates existed config

Parameters:

  • scheme_name (String)

    Scheme name

  • config (Hash)

    Config to set/update

Since:

  • 0.2.0



32
33
34
35
# File 'lib/jafry/configurator.rb', line 32

def init_or_update(scheme_name, config)
  return find_config(scheme_name)[:config].merge!(config) if find_config(scheme_name)
  {scheme: scheme_name, config: config}
end

.set_config(scheme_name, config = {}) ⇒ Object

Setups config for scheme

Parameters:

  • scheme_name (String)

    Scheme name

  • config (Hash) (defaults to: {})

    Config

Since:

  • 0.2.0



20
21
22
23
24
25
# File 'lib/jafry/configurator.rb', line 20

def set_config(scheme_name, config={})
  config = default if config.empty?
  scheme_config = init_or_update(scheme_name, config)
  self.schemes_configs << scheme_config
  scheme_config
end