Module: Configurations::Arbitrary
- Defined in:
- lib/configurations/arbitrary.rb
Overview
Configuration is a blank object in order to allow configuration of various properties including keywords
Instance Method Summary collapse
-
#__configurable?(_property) ⇒ Boolean
Whether the given property is configurable.
-
#__writeable__=(data) ⇒ Object
Set the configuration to writeable or read only.
-
#from_h(h) ⇒ Configuration
A convenience accessor to instantiate a configuration from a hash.
-
#initialize(options = {}, &block) {|HostModule::Configuration| ... } ⇒ HostModule::Configuration
Initialize a new configuration.
-
#method_missing(method, *args, &block) ⇒ Object
Method missing gives access for reading and writing to the underlying configuration hash via dot notation.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Respond to missing according to the method_missing implementation.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Method missing gives access for reading and writing to the underlying configuration hash via dot notation
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/configurations/arbitrary.rb', line 27 def method_missing(method, *args, &block) if __respond_to_writer?(method) __assign!(method.to_s[0..-2].to_sym, args.first) elsif __respond_to_method_for_write?(method) @data[method] elsif __respond_to_method_for_read?(method, *args, &block) @data.fetch(method, &__not_configured_callback_for__(method)) else super end end |
Instance Method Details
#__configurable?(_property) ⇒ Boolean
Returns whether the given property is configurable.
67 68 69 |
# File 'lib/configurations/arbitrary.rb', line 67 def __configurable?(_property) true end |
#__writeable__=(data) ⇒ Object
Set the configuration to writeable or read only. Access to writer methods is only allowed within the configure block, this method is used to invoke writeability for subconfigurations.
77 78 79 80 81 82 83 84 |
# File 'lib/configurations/arbitrary.rb', line 77 def __writeable__=(data) @__writeable__ = data return if @data.nil? @data.each do |_k, v| v.__writeable__ = data if v.is_a?(__class__) end end |
#from_h(h) ⇒ Configuration
can only be accessed during writeable state (in configure block). Unassignable values are ignored
A convenience accessor to instantiate a configuration from a hash
56 57 58 59 60 61 62 |
# File 'lib/configurations/arbitrary.rb', line 56 def from_h(h) unless @__writeable__ fail ::ArgumentError, 'can not dynamically assign values from a hash' end super end |
#initialize(options = {}, &block) {|HostModule::Configuration| ... } ⇒ HostModule::Configuration
An arbitrary configuration has to control its writeable state, therefore configuration is only possible in the initialization block
Initialize a new configuration
18 19 20 21 22 |
# File 'lib/configurations/arbitrary.rb', line 18 def initialize( = {}, &block) self.__writeable__ = true super self.__writeable__ = false if block end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Respond to missing according to the method_missing implementation
41 42 43 44 45 46 |
# File 'lib/configurations/arbitrary.rb', line 41 def respond_to_missing?(method, include_private = false) __respond_to_writer?(method) || __respond_to_method_for_read?(method, *args, &block) || __respond_to_method_for_write?(method) || super end |