Class: SpecForge::Configuration
- Inherits:
-
Object
- Object
- SpecForge::Configuration
- Defined in:
- lib/spec_forge/configuration.rb
Overview
Holds configuration options for SpecForge
Configuration is typically set in forge_helper.rb using the configure block. It controls base URL, global variables, factory settings, callbacks, and more.
Defined Under Namespace
Classes: Factories
Instance Attribute Summary collapse
-
#base_url ⇒ String
Base URL for HTTP requests.
-
#callbacks ⇒ Hash{Symbol => Proc}
readonly
Registered callbacks.
-
#factories ⇒ Factories
readonly
Factory configuration.
-
#global_variables ⇒ Hash
Global variables available to all blueprints.
-
#hooks ⇒ Hash{Symbol => Array}
readonly
Global lifecycle hooks for forge, blueprint, and step events.
-
#on_debug_proc ⇒ Proc?
readonly
Debug handler proc.
Instance Method Summary collapse
-
#after(event, callback_name = nil) {|context| ... } ⇒ String, Symbol
Attaches a callback to an after lifecycle event.
-
#before(event, callback_name = nil) {|context| ... } ⇒ String, Symbol
Attaches a callback to a before lifecycle event.
-
#deregister_callback(name) ⇒ Proc?
Removes a registered callback and detaches it from all lifecycle hooks.
-
#initialize ⇒ Configuration
constructor
Creates a new Configuration with default values.
-
#on_debug {|context| ... } ⇒ Object
Sets a debug handler block to be called when a step has debug: true.
-
#register_callback(name) {|context, *args| ... } ⇒ Object
Registers a callback that can be invoked from blueprints using call:.
-
#rspec ⇒ RSpec::Core::Configuration
Returns RSpec's configuration for customization.
-
#validate ⇒ Configuration
Validates the configuration and normalizes values.
Constructor Details
#initialize ⇒ Configuration
Creates a new Configuration with default values
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/spec_forge/configuration.rb', line 53 def initialize # Validated @base_url = "http://localhost:3000" @factories = Factories.new @global_variables = {} # Internal @on_debug_proc = nil @callbacks = {} @hooks = { before_forge: [], before_blueprint: [], before_step: [], after_step: [], after_blueprint: [], after_forge: [] } end |
Instance Attribute Details
#base_url ⇒ String
Returns Base URL for HTTP requests.
31 32 33 |
# File 'lib/spec_forge/configuration.rb', line 31 def base_url @base_url end |
#callbacks ⇒ Hash{Symbol => Proc} (readonly)
Returns Registered callbacks.
43 44 45 |
# File 'lib/spec_forge/configuration.rb', line 43 def callbacks @callbacks end |
#factories ⇒ Factories (readonly)
Returns Factory configuration.
37 38 39 |
# File 'lib/spec_forge/configuration.rb', line 37 def factories @factories end |
#global_variables ⇒ Hash
Returns Global variables available to all blueprints.
34 35 36 |
# File 'lib/spec_forge/configuration.rb', line 34 def global_variables @global_variables end |
#hooks ⇒ Hash{Symbol => Array} (readonly)
Returns Global lifecycle hooks for forge, blueprint, and step events.
46 47 48 |
# File 'lib/spec_forge/configuration.rb', line 46 def hooks @hooks end |
#on_debug_proc ⇒ Proc? (readonly)
Returns Debug handler proc.
40 41 42 |
# File 'lib/spec_forge/configuration.rb', line 40 def on_debug_proc @on_debug_proc end |
Instance Method Details
#after(event, callback_name = nil) {|context| ... } ⇒ String, Symbol
Attaches a callback to an after lifecycle event
Global hooks run for all blueprints and execute in registration order. Can either reference a pre-registered callback by name, or accept a block to register and attach a callback in one step (like RSpec's after hooks).
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/spec_forge/configuration.rb', line 234 def after(event, callback_name = nil, &block) if block callback_name = "__sf_cb_#{SecureRandom.uuid.tr("-", "")}" register_callback(callback_name, &block) end register_hook("after", event, callback_name) callback_name end |
#before(event, callback_name = nil) {|context| ... } ⇒ String, Symbol
Attaches a callback to a before lifecycle event
Global hooks run for all blueprints and execute in registration order. Can either reference a pre-registered callback by name, or accept a block to register and attach a callback in one step (like RSpec's before hooks).
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/spec_forge/configuration.rb', line 192 def before(event, callback_name = nil, &block) if block callback_name = "__sf_cb_#{SecureRandom.uuid.tr("-", "")}" register_callback(callback_name, &block) end register_hook("before", event, callback_name) callback_name end |
#deregister_callback(name) ⇒ Proc?
Removes a registered callback and detaches it from all lifecycle hooks
152 153 154 155 156 157 158 159 |
# File 'lib/spec_forge/configuration.rb', line 152 def deregister_callback(name) name = name.to_sym callback = @callbacks.delete(name) @hooks.each_value { |a| a.delete(name) } callback end |
#on_debug {|context| ... } ⇒ Object
Sets a debug handler block to be called when a step has debug: true
105 106 107 |
# File 'lib/spec_forge/configuration.rb', line 105 def on_debug(&block) @on_debug_proc = block end |
#register_callback(name) {|context, *args| ... } ⇒ Object
Registers a callback that can be invoked from blueprints using call:
136 137 138 |
# File 'lib/spec_forge/configuration.rb', line 136 def register_callback(name, &block) @callbacks[name.to_sym] = block end |
#rspec ⇒ RSpec::Core::Configuration
Returns RSpec's configuration for customization
114 115 116 |
# File 'lib/spec_forge/configuration.rb', line 114 def rspec RSpec.configuration end |
#validate ⇒ Configuration
Validates the configuration and normalizes values
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/spec_forge/configuration.rb', line 79 def validate output = Normalizer.normalize!( { base_url: @base_url, factories: @factories.to_h, global_variables: @global_variables }, using: :configuration ) # In case any value was set to `nil` @global_variables = output[:global_variables] if @global_variables.blank? @global_variables.symbolize_keys! self end |