Class: FigFig::ConfigurationContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/fig_fig.rb

Overview

The class that encapsulates the current configuration definition and parameter values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurationContainer

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_callbacksObject

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

#configuringObject

Returns the value of attribute configuring.



43
44
45
# File 'lib/fig_fig.rb', line 43

def configuring
  @configuring
end

#parametersObject

Returns the value of attribute parameters.



43
44
45
# File 'lib/fig_fig.rb', line 43

def parameters
  @parameters
end

#readiedObject

Returns the value of attribute readied.



43
44
45
# File 'lib/fig_fig.rb', line 43

def readied
  @readied
end

#validatedObject

Returns the value of attribute validated.



43
44
45
# File 'lib/fig_fig.rb', line 43

def validated
  @validated
end

#validatingObject

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

Returns:

  • (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, options = {})
  @parameters ||= []
  raise DuplicateParameterDefinitionError if parameters.any? { |p| p.keys.first == name }
  parameters << { name: name.to_s, options: options, value: nil, set: false }
end

#readyObject



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

Returns:

  • (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

Returns:

  • (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