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
- #config(name, coerce: nil, default: nil, required: false, &block) ⇒ Object private
- #config_blocks ⇒ Object private
- #config_coercions ⇒ Object private
- #config_defaults ⇒ Object private
- #config_required_keys ⇒ Object private
- #config_struct ⇒ Object private
- #config_variable(name) ⇒ Object private
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.
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_blocks ⇒ 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.
44 45 46 |
# File 'lib/moneta/config.rb', line 44 def config_blocks config_variable(:@config_blocks) || {} end |
#config_coercions ⇒ 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.
40 41 42 |
# File 'lib/moneta/config.rb', line 40 def config_coercions config_variable(:@config_coercions) || {} end |
#config_defaults ⇒ 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.
32 33 34 |
# File 'lib/moneta/config.rb', line 32 def config_defaults config_variable(:@config_defaults) || {} end |
#config_required_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.
36 37 38 |
# File 'lib/moneta/config.rb', line 36 def config_required_keys config_variable(:@config_required_keys) || Set.new end |
#config_struct ⇒ 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.
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 |