Class: Pakyow::Support::Configurable::Config Private

Inherits:
Object
  • Object
show all
Extended by:
DeepFreeze
Defined in:
lib/pakyow/support/configurable/config.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.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeepFreeze

extended, inherited, unfreezable

Constructor Details

#initialize(configurable) ⇒ Config

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 Config.

API:

  • private



23
24
25
26
27
28
29
# File 'lib/pakyow/support/configurable/config.rb', line 23

def initialize(configurable)
  @configurable = configurable

  @__settings = Concurrent::Hash.new
  @__defaults = Concurrent::Hash.new
  @__groups   = Concurrent::Hash.new
end

Instance Attribute Details

#__defaultsObject (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.

API:

  • private



21
22
23
# File 'lib/pakyow/support/configurable/config.rb', line 21

def __defaults
  @__defaults
end

#__groupsObject (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.

API:

  • private



21
22
23
# File 'lib/pakyow/support/configurable/config.rb', line 21

def __groups
  @__groups
end

#__settingsObject (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.

API:

  • private



21
22
23
# File 'lib/pakyow/support/configurable/config.rb', line 21

def __settings
  @__settings
end

Instance Method Details

#configurable(group, &block) ⇒ 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.

API:

  • private



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pakyow/support/configurable/config.rb', line 64

def configurable(group, &block)
  group = group.to_sym
  config = Config.new(@configurable)
  config.instance_eval(&block)

  unless @__groups.include?(group)
    define_group_methods(group)
  end

  @__groups[group] = config
end

#configure_defaults!(configured_environment) ⇒ 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.

API:

  • private



76
77
78
79
80
81
82
83
84
# File 'lib/pakyow/support/configurable/config.rb', line 76

def configure_defaults!(configured_environment)
  if defaults = @__defaults[configured_environment.to_s.to_sym]
    instance_eval(&defaults)
  end

  @__groups.values.each do |group|
    group.configure_defaults!(configured_environment)
  end
end

#defaults(environment, &block) ⇒ 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.

API:

  • private



60
61
62
# File 'lib/pakyow/support/configurable/config.rb', line 60

def defaults(environment, &block)
  @__defaults[environment] = block
end

#eval(setting, context) ⇒ 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.

API:

  • private



112
113
114
115
116
117
118
119
# File 'lib/pakyow/support/configurable/config.rb', line 112

def eval(setting, context)
  value = public_send(setting)
  if value.is_a?(Proc)
    context.instance_eval(&value)
  else
    value
  end
end

#initialize_copy(_) ⇒ 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.

API:

  • private



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pakyow/support/configurable/config.rb', line 31

def initialize_copy(_)
  @__defaults = @__defaults.deep_dup
  @__settings = @__settings.deep_dup
  @__groups   = @__groups.deep_dup

  @__settings.each do |key, _|
    define_setting_methods(key)
  end

  @__groups.each do |key, _|
    define_group_methods(key)
  end

  super
end

#setting(name, default = default_omitted = true, &block) ⇒ 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.

API:

  • private



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pakyow/support/configurable/config.rb', line 47

def setting(name, default = default_omitted = true, &block)
  tap do
    name = name.to_sym
    default = nil if default_omitted

    unless @__settings.include?(name)
      define_setting_methods(name)
    end

    @__settings[name] = Setting.new(default: default, configurable: @configurable, &block)
  end
end

#to_hObject

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.

API:

  • private



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/pakyow/support/configurable/config.rb', line 98

def to_h
  hash = {}

  @__settings.each_with_object(hash) { |(name, setting), h|
    h[name] = setting.value
  }

  @__groups.each_with_object(hash) { |(name, group), h|
    h[name] = group.to_h
  }

  hash
end

#update_configurable(configurable) ⇒ 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.

API:

  • private



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pakyow/support/configurable/config.rb', line 86

def update_configurable(configurable)
  @configurable = configurable

  @__settings.values.each do |setting|
    setting.update_configurable(configurable)
  end

  @__groups.values.each do |group|
    group.update_configurable(configurable)
  end
end