Module: Configurations::Configurable::ClassMethods
- Defined in:
- lib/configurations/configurable.rb
Overview
Class methods that will get installed in the host module
Instance Method Summary collapse
-
#configurable(*properties, &block) ⇒ Object
configurable can be used to set the properties which should be configurable, as well as a type which the given property should be asserted to.
-
#configurable?(property) ⇒ Boolean
returns whether a property is set to be configurable.
-
#configuration_defaults(&block) ⇒ Object
Configuration defaults can be used to set the defaults of any Configuration.
-
#configuration_method(method, &block) ⇒ Object
configuration method can be used to retrieve properties from the configuration which use your gem’s context.
- #extract_type(properties) ⇒ Object
-
#not_configured(*properties, &block) {|Symbol| ... } ⇒ Object
not_configured defines the behaviour when a property has not been configured.
Instance Method Details
#configurable(*properties, &block) ⇒ Object
configurable can be used to set the properties which should be configurable, as well as a type which the given property should be asserted to
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/configurations/configurable.rb', line 119 def configurable(*properties, &block) @configurable_properties ||= Maps::Properties.new @configurable_types ||= Maps::Types.new @configurable_blocks ||= Maps::Blocks.new type, properties = extract_type(properties) @configurable_properties.add(properties) @configurable_types.add(type, properties) @configurable_blocks.add(block, properties) end |
#configurable?(property) ⇒ Boolean
returns whether a property is set to be configurable
142 143 144 145 146 |
# File 'lib/configurations/configurable.rb', line 142 def configurable?(property) defined?(@configurable_properties) && @configurable_properties && @configurable_properties.configurable?(Path.new([property])) end |
#configuration_defaults(&block) ⇒ Object
Configuration defaults can be used to set the defaults of any Configuration
97 98 99 |
# File 'lib/configurations/configurable.rb', line 97 def configuration_defaults(&block) @configuration_defaults = block end |
#configuration_method(method, &block) ⇒ Object
configuration method can be used to retrieve properties from the configuration which use your gem’s context
162 163 164 165 166 167 168 169 170 |
# File 'lib/configurations/configurable.rb', line 162 def configuration_method(method, &block) fail( ArgumentError, "can't be configuration property and a method" ) if configurable?(method) @configuration_method_blocks ||= Maps::Blocks.new @configuration_method_blocks.add(block, [method]) end |
#extract_type(properties) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/configurations/configurable.rb', line 130 def extract_type(properties) if properties.first.is_a?(Module) [properties.first, properties[1...properties.size]] else [nil, properties] end end |
#not_configured(*properties, &block) {|Symbol| ... } ⇒ Object
not_configured defines the behaviour when a property has not been configured. This can be useful for presence validations of certain properties or behaviour for undefined properties deviating from the original behaviour.
191 192 193 194 195 196 197 198 |
# File 'lib/configurations/configurable.rb', line 191 def not_configured(*properties, &block) @not_configured_blocks ||= Maps::Blocks.new @not_configured_blocks.add(block, properties) if properties.empty? @not_configured_blocks.add_default(block) end end |