Module: SleepingKingStudios::Tools::Toolbox::Configuration::ClassMethods
- Included in:
- SleepingKingStudios::Tools::Toolbox::Configuration
- Defined in:
- lib/sleeping_king_studios/tools/toolbox/configuration.rb
Overview
Class methods for configuration objects.
Constant Summary collapse
- DEFAULT_OPTION =
Object.new.freeze
Instance Method Summary collapse
-
#namespace(namespace_name) { ... } ⇒ Configuration
Defines a nested namespace for the configuration object.
-
#option(option_name, allow_nil: false, default: DEFAULT_OPTION, enum: nil) ⇒ Object
Defines an option for the configuration object.
Instance Method Details
#namespace(namespace_name) { ... } ⇒ Configuration
Defines a nested namespace for the configuration object.
A namespace is represented by a nested configuration object, which has its own options and namespaces.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 24 def namespace(namespace_name, &block) guard_abstract_class! namespace = (@namespaces ||= {}).fetch(namespace_name) do @namespaces[namespace_name] = define_namespace namespace_name end namespace.instance_exec(namespace, &block) if block_given? namespace end |
#option(option_name, allow_nil: false, default: DEFAULT_OPTION, enum: nil) ⇒ Object
Defines an option for the configuration object.
A configuration option has a name and a value. It can be defined with a default value, or to allow or prohibit nil values or restrict possible values to a given set.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 50 def option( option_name, allow_nil: false, default: DEFAULT_OPTION, enum: nil ) guard_abstract_class! = { allow_nil: allow_nil, default: default, enum: enum } define_option_accessor option_name, define_option_mutator option_name, option_name.intern end |