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
-
#__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 38 39 |
# 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) do @not_configured_blocks.evaluate!(@path.add(method), method) end else super end end |
Instance Method Details
#__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.
72 73 74 75 76 77 78 79 |
# File 'lib/configurations/arbitrary.rb', line 72 def __writeable__=(data) @writeable = data return unless defined?(@data) && @data @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
58 59 60 61 62 63 64 |
# File 'lib/configurations/arbitrary.rb', line 58 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
43 44 45 46 47 48 |
# File 'lib/configurations/arbitrary.rb', line 43 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 |