Module: Moneta::Config::ClassMethods Private

Defined in:
lib/moneta/config.rb

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

Instance Method Summary collapse

Instance Method Details

#config(name, coerce: nil, default: nil, required: false, &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.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/moneta/config.rb', line 8

def config(name, coerce: nil, default: nil, required: false, &block)
  raise ArgumentError, 'name must be a symbol' unless Symbol === name

  defaults = config_defaults

  raise ArgumentError, "#{name} is already a config option" if defaults.key?(name)
  raise ArgumentError, "coerce must respond to :to_proc" if coerce && !coerce.respond_to?(:to_proc)

  defaults.merge!(name => default.freeze).freeze
  instance_variable_set :@config_defaults, defaults

  instance_variable_set :@config_coercions, config_coercions.merge!(name => coerce.to_proc) if coerce
  instance_variable_set :@config_required_keys, config_required_keys.add(name).freeze if required
  instance_variable_set :@config_blocks, config_blocks.merge!(name => block) if block
end

#config_blocksObject

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.



44
45
46
# File 'lib/moneta/config.rb', line 44

def config_blocks
  config_variable(:@config_blocks) || {}
end

#config_coercionsObject

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.



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

def config_coercions
  config_variable(:@config_coercions) || {}
end

#config_defaultsObject

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.



32
33
34
# File 'lib/moneta/config.rb', line 32

def config_defaults
  config_variable(:@config_defaults) || {}
end

#config_required_keysObject

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.



36
37
38
# File 'lib/moneta/config.rb', line 36

def config_required_keys
  config_variable(:@config_required_keys) || Set.new
end

#config_structObject

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.



48
49
50
51
52
53
54
55
# File 'lib/moneta/config.rb', line 48

def config_struct
  unless @config_struct
    keys = config_defaults.keys
    @config_struct = Struct.new(*keys) unless keys.empty?
  end

  @config_struct
end

#config_variable(name) ⇒ 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.



24
25
26
27
28
29
30
# File 'lib/moneta/config.rb', line 24

def config_variable(name)
  if instance_variable_defined?(name)
    instance_variable_get(name).dup
  elsif superclass.respond_to?(:config_variable)
    superclass.config_variable(name)
  end
end