Class: Qonfig::Settings Private

Inherits:
Object
  • Object
show all
Defined in:
lib/qonfig/settings.rb,
lib/qonfig/settings/lock.rb,
lib/qonfig/settings/builder.rb,
lib/qonfig/settings/key_guard.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Defined Under Namespace

Modules: Builder Classes: KeyGuard, Lock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Settings.

Since:

  • 0.1.0



17
18
19
20
# File 'lib/qonfig/settings.rb', line 17

def initialize
  @__options__ = {}
  @__lock__ = Lock.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • method_name (String, Symbol)
  • arguments (Array<Object>)
  • block (Proc)

Raises:

Since:

  • 0.1.0



123
124
125
126
127
# File 'lib/qonfig/settings.rb', line 123

def method_missing(method_name, *arguments, &block)
  super
rescue NoMethodError
  ::Kernel.raise(Qonfig::UnknownSettingError, "Setting with <#{method_name}> key doesnt exist!")
end

Instance Attribute Details

#__options__Hash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)

Since:

  • 0.1.0



13
14
15
# File 'lib/qonfig/settings.rb', line 13

def __options__
  @__options__
end

Instance Method Details

#[](key) ⇒ Object

Parameters:

  • key (Symbol, String)

Returns:

  • (Object)

Since:

  • 0.1.0



65
66
67
# File 'lib/qonfig/settings.rb', line 65

def [](key)
  __lock__.thread_safe_access { __get_value__(key) }
end

#[]=(key, value) ⇒ void

This method returns an undefined value.

Parameters:

  • key (String, Symbol)
  • value (Object)

Since:

  • 0.1.0



75
76
77
# File 'lib/qonfig/settings.rb', line 75

def []=(key, value)
  __lock__.thread_safe_access { __set_value__(key, value) }
end

#__append_settings__(settings) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0



52
53
54
55
56
57
58
# File 'lib/qonfig/settings.rb', line 52

def __append_settings__(settings)
  __lock__.thread_safe_merge do
    settings.__options__.each_pair do |key, value|
      __define_setting__(key, value)
    end
  end
end

#__apply_values__(options_map) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • options_map (Hash)

Since:

  • 0.3.0



84
85
86
# File 'lib/qonfig/settings.rb', line 84

def __apply_values__(options_map)
  __lock__.thread_safe_access { __set_values_from_map__(options_map) }
end

#__clear__void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Since:

  • 0.2.0



110
111
112
# File 'lib/qonfig/settings.rb', line 110

def __clear__
  __lock__.thread_safe_access { __clear_option_values__ }
end

#__define_setting__(key, value) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (Symbol, String)
  • value (Object)

Since:

  • 0.1.0



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/qonfig/settings.rb', line 28

def __define_setting__(key, value)
  __lock__.thread_safe_definition do
    key = __indifferently_accessable_option_key__(key)

    __prevent_core_method_intersection__(key)

    case
    when !__options__.key?(key)
      __options__[key] = value
    when __options__[key].is_a?(Qonfig::Settings) && value.is_a?(Qonfig::Settings)
      __options__[key].__append_settings__(value)
    else
      __options__[key] = value
    end

    __define_accessor__(key)
  end
end

#__dig__(*keys) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • keys (Array<String, Symbol>)

Returns:

  • (Object)

Since:

  • 0.2.0



93
94
95
# File 'lib/qonfig/settings.rb', line 93

def __dig__(*keys)
  __lock__.thread_safe_access { __deep_access__(*keys) }
end

#__freeze__void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Since:

  • 0.1.0



143
144
145
146
147
148
149
150
151
# File 'lib/qonfig/settings.rb', line 143

def __freeze__
  __lock__.thread_safe_access do
    __options__.freeze

    __options__.each_value do |value|
      value.__freeze__ if value.is_a?(Qonfig::Settings)
    end
  end
end

#__is_frozen__Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.2.0



157
158
159
# File 'lib/qonfig/settings.rb', line 157

def __is_frozen__
  __lock__.thread_safe_access { __options__.frozen? }
end

#__to_hash__Hash Also known as: __to_h__

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)

Since:

  • 0.1.0



101
102
103
# File 'lib/qonfig/settings.rb', line 101

def __to_hash__
  __lock__.thread_safe_access { __build_hash_representation__ }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



133
134
135
136
137
# File 'lib/qonfig/settings.rb', line 133

def respond_to_missing?(method_name, include_private = false)
  # :nocov:
  __options__.key?(method_name.to_s) || __options__.key?(method_name.to_sym) || super
  # :nocov:
end