Class: SpecForge::Attribute::ResolvableArray
- Includes:
- Resolvable
- Defined in:
- lib/spec_forge/attribute/resolvable_array.rb
Overview
Represents an array that may contain attributes that need resolution
This class extends Array and provides methods to recursively resolve any attribute objects contained within it. It allows arrays to contain dynamic content like variables and faker values.
Instance Method Summary collapse
-
#initialize(array = []) ⇒ ResolvableArray
constructor
Creates a new ResolvableArray from the given array.
-
#resolve ⇒ Array
Freshly resolves all items in the array.
-
#resolve_as_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher
Converts all items in the array to RSpec matchers.
-
#resolved ⇒ Array
Returns a new array with all items fully resolved to their final values.
-
#value ⇒ Array
Returns the underlying array.
Methods included from Resolvable
#resolve_as_matcher_proc, #resolve_proc, #resolved_proc
Methods inherited from Array
Constructor Details
#initialize(array = []) ⇒ ResolvableArray
Creates a new ResolvableArray from the given array
25 26 27 |
# File 'lib/spec_forge/attribute/resolvable_array.rb', line 25 def initialize(array = []) super end |
Instance Method Details
#resolve ⇒ Array
Freshly resolves all items in the array. Unlike #resolved, this doesn't use cached values, ensuring fresh resolution.
62 63 64 |
# File 'lib/spec_forge/attribute/resolvable_array.rb', line 62 def resolve map(&resolve_proc) end |
#resolve_as_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher
Converts all items in the array to RSpec matchers. First converts each array element to a matcher using resolve_as_matcher_proc, then wraps the entire result in a matcher suitable for array comparison.
This ensures all elements in the array are proper matchers, which is essential for compound matchers and proper failure messages.
80 81 82 83 |
# File 'lib/spec_forge/attribute/resolvable_array.rb', line 80 def resolve_as_matcher result = map(&resolve_as_matcher_proc) Attribute::Literal.new(result).resolve_as_matcher end |
#resolved ⇒ Array
Returns a new array with all items fully resolved to their final values. Uses the cached version of each item if available.
48 49 50 |
# File 'lib/spec_forge/attribute/resolvable_array.rb', line 48 def resolved map(&resolved_proc) end |
#value ⇒ Array
Returns the underlying array
34 35 36 |
# File 'lib/spec_forge/attribute/resolvable_array.rb', line 34 def value self end |