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 ⇒ Object
A reader for Configuration.
-
#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.
-
#configuration_type ⇒ Object
The class name of the configuration class to use.
-
#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
75 76 77 78 79 80 |
# File 'lib/configurations/configurable.rb', line 75 def configurable(*properties, &block) type = properties.shift if properties.first.is_a?(Class) @configurable ||= {} @configurable.merge! to_configurable_hash(properties, type, &block) end |
#configurable?(property) ⇒ Boolean
returns whether a property is set to be configurable
86 87 88 |
# File 'lib/configurations/configurable.rb', line 86 def configurable?(property) @configurable.is_a?(Hash) && @configurable.key?(property) end |
#configuration ⇒ Object
A reader for Configuration
45 46 47 |
# File 'lib/configurations/configurable.rb', line 45 def configuration @configuration ||= @configuration_defaults && configure {} end |
#configuration_defaults(&block) ⇒ Object
Configuration defaults can be used to set the defaults of any Configuration
53 54 55 |
# File 'lib/configurations/configurable.rb', line 53 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
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/configurations/configurable.rb', line 104 def configuration_method(method, &block) fail ArgumentError, "can't be configuration property and a method" if configurable?(method) @configuration_methods ||= {} method_hash = if method.is_a?(Hash) ingest_configuration_block!(method, &block) else { method => block } end @configuration_methods.merge! method_hash end |
#configuration_type ⇒ Object
Returns the class name of the configuration class to use.
148 149 150 151 152 153 154 |
# File 'lib/configurations/configurable.rb', line 148 def configuration_type if @configurable.nil? || @configurable.empty? :ArbitraryConfiguration else :StrictConfiguration 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.
136 137 138 139 140 141 142 143 144 |
# File 'lib/configurations/configurable.rb', line 136 def not_configured(*properties, &block) @not_configured ||= {} if properties.empty? @not_configured.default_proc = ->(h, k) { h[k] = block } else nested_merge_not_configured_hash(*properties, &block) end end |