Class: FigFig::ConfigurationContainer
- Inherits:
-
Object
- Object
- FigFig::ConfigurationContainer
- Defined in:
- lib/fig_fig.rb
Overview
The class that encapsulates the current configuration definition and parameter values
Instance Attribute Summary collapse
-
#after_validation_callbacks ⇒ Object
Returns the value of attribute after_validation_callbacks.
-
#configuring ⇒ Object
Returns the value of attribute configuring.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#readied ⇒ Object
Returns the value of attribute readied.
-
#validated ⇒ Object
Returns the value of attribute validated.
-
#validating ⇒ Object
Returns the value of attribute validating.
Instance Method Summary collapse
- #after_validation(&blk) ⇒ Object
-
#initialize ⇒ ConfigurationContainer
constructor
A new instance of ConfigurationContainer.
- #locked?(parameter) ⇒ Boolean
- #method_missing(method_name, *args, &blk) ⇒ Object
- #parameter(name, options = {}) ⇒ Object
- #ready ⇒ Object
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ ConfigurationContainer
Returns a new instance of ConfigurationContainer.
50 51 52 53 |
# File 'lib/fig_fig.rb', line 50 def initialize @configuring = false @validating = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/fig_fig.rb', line 94 def method_missing(method_name, *args, &blk) method_name_str = method_name.to_s return super unless _dynamically_exposed_methods.include? method_name_str if _dynamically_exposed_readers.include? method_name_str _ghost_reader method_name_str, *args, &blk elsif _dynamically_exposed_writers.include? method_name_str _ghost_writer method_name_str, *args, &blk end end |
Instance Attribute Details
#after_validation_callbacks ⇒ Object
Returns the value of attribute after_validation_callbacks.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def after_validation_callbacks @after_validation_callbacks end |
#configuring ⇒ Object
Returns the value of attribute configuring.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def configuring @configuring end |
#parameters ⇒ Object
Returns the value of attribute parameters.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def parameters @parameters end |
#readied ⇒ Object
Returns the value of attribute readied.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def readied @readied end |
#validated ⇒ Object
Returns the value of attribute validated.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def validated @validated end |
#validating ⇒ Object
Returns the value of attribute validating.
43 44 45 |
# File 'lib/fig_fig.rb', line 43 def validating @validating end |
Instance Method Details
#after_validation(&blk) ⇒ Object
89 90 91 92 |
# File 'lib/fig_fig.rb', line 89 def after_validation(&blk) @after_validation_callbacks ||= [] @after_validation_callbacks << blk end |
#locked?(parameter) ⇒ Boolean
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/fig_fig.rb', line 108 def locked?(parameter) lock_option = parameter[:options].fetch(:lock, nil) case lock_option when nil false when :on_set parameter[:set] when :on_validation validated when :on_ready readied else raise InvalidLockOptionError end end |
#parameter(name, options = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/fig_fig.rb', line 55 def parameter(name, = {}) @parameters ||= [] raise DuplicateParameterDefinitionError if parameters.any? { |p| p.keys.first == name } parameters << { name: name.to_s, options: , value: nil, set: false } end |
#ready ⇒ Object
80 81 82 83 |
# File 'lib/fig_fig.rb', line 80 def ready valid? @readied = true end |
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
104 105 106 |
# File 'lib/fig_fig.rb', line 104 def respond_to_missing?(method_name, _include_private = false) _dynamically_exposed_methods.include?(method_name.to_s) || super end |
#valid? ⇒ Boolean
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fig_fig.rb', line 61 def valid? @validating = true _missing_configuration if _invalid_parameters.any? # Set validated to true to block changes to parameters with on_validation locks # including those in after_validation callbacks @validated = true Array(@after_validation_callbacks).each do |callback| callback.call self end # Below line is the final_validation lifecycle event _missing_configuration if _invalid_parameters.any? @validating = false @validated end |