Class: SpecForge::Attribute::ResolvableHash
- Inherits:
-
Hash
- Object
- Hash
- SpecForge::Attribute::ResolvableHash
- Includes:
- Resolvable
- Defined in:
- lib/spec_forge/attribute/resolvable_hash.rb
Overview
Represents a hash that may contain attributes that need resolution
This class extends Hash and provides methods to recursively resolve any attribute objects contained within it. It allows hashes to contain dynamic content like variables and faker values.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ ResolvableHash
constructor
Creates a new ResolvableHash from the given hash.
-
#resolve ⇒ Hash
Freshly resolves all values in the hash.
-
#resolve_as_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher
Converts all values in the hash to RSpec matchers.
-
#resolved ⇒ Hash
Returns a new hash with all values fully resolved to their final values.
-
#value ⇒ Hash
Returns the underlying hash.
Methods included from Resolvable
#resolve_as_matcher_proc, #resolve_proc, #resolved_proc
Constructor Details
#initialize(hash = {}) ⇒ ResolvableHash
Creates a new ResolvableHash from the given hash
25 26 27 28 |
# File 'lib/spec_forge/attribute/resolvable_hash.rb', line 25 def initialize(hash = {}) super() merge!(hash) end |
Instance Method Details
#resolve ⇒ Hash
Freshly resolves all values in the hash. Unlike #resolved, this doesn't use cached values, ensuring fresh resolution.
63 64 65 |
# File 'lib/spec_forge/attribute/resolvable_hash.rb', line 63 def resolve transform_values(&resolve_proc) end |
#resolve_as_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher
Converts all values in the hash to RSpec matchers. Transforms each hash value to a matcher using resolve_as_matcher_proc, then wraps the entire result in a matcher suitable for hash comparison.
This ensures proper nesting of matchers in hash structures, which is vital for readable failure messages in complex expectations.
81 82 83 84 |
# File 'lib/spec_forge/attribute/resolvable_hash.rb', line 81 def resolve_as_matcher result = transform_values(&resolve_as_matcher_proc) Attribute::Literal.new(result).resolve_as_matcher end |
#resolved ⇒ Hash
Returns a new hash with all values fully resolved to their final values. Uses the cached version of each value if available.
49 50 51 |
# File 'lib/spec_forge/attribute/resolvable_hash.rb', line 49 def resolved transform_values(&resolved_proc) end |
#value ⇒ Hash
Returns the underlying hash
35 36 37 |
# File 'lib/spec_forge/attribute/resolvable_hash.rb', line 35 def value self end |