Module: SpecForge::Attribute::Resolvable

Included in:
SpecForge::Attribute, SpecForge::Attribute, ResolvableArray, ResolvableHash, ResolvableStruct
Defined in:
lib/spec_forge/attribute/resolvable.rb

Overview

Provides helper methods for resolving attributes

This module contains shared logic for handling attribute resolution in collection types. It defines procs that can be used with map and transform operations to recursively resolve nested attributes.

Instance Method Summary collapse

Instance Method Details

#resolve_as_matcher_procProc

Returns a proc that resolves attributes into their matcher form. For objects that respond to #resolve_as_matcher, calls that method. For other objects, simply returns them unchanged.

Examples:

proc = resolve_as_matcher_proc
proc.call(Attribute::Faker.new("faker.name.name")) # => eq("John Doe")
proc.call(Attribute::Regex.new("/hello/")) # => match(/hello/)

Returns:

  • (Proc)

    A proc for resolving attributes to matchers



57
58
59
# File 'lib/spec_forge/attribute/resolvable.rb', line 57

def resolve_as_matcher_proc
  ->(v) { v.respond_to?(:resolve_as_matcher) ? v.resolve_as_matcher : v }
end

#resolve_procProc

Returns a proc that freshly resolves objects. For objects that respond to #resolve, calls that method. For other objects, simply returns them unchanged.

Examples:

proc = resolve_proc
proc.call(Attribute::Faker.new("faker.name.name")) # => "John Smith" (fresh)
proc.call("already resolved") # => "already resolved" (unchanged)

Returns:

  • (Proc)

    A proc for freshly resolving objects



41
42
43
# File 'lib/spec_forge/attribute/resolvable.rb', line 41

def resolve_proc
  ->(v) { v.respond_to?(:resolve) ? v.resolve : v }
end

#resolved_procProc

Returns a proc that resolves objects to their cached final values. For objects that respond to #resolved, calls that method. For other objects, simply returns them unchanged.

Examples:

proc = resolved_proc
proc.call(Attribute::Faker.new("faker.name.name")) # => "Jane Doe" (cached)
proc.call("already resolved") # => "already resolved" (unchanged)

Returns:

  • (Proc)

    A proc for resolving objects to their cached final values



25
26
27
# File 'lib/spec_forge/attribute/resolvable.rb', line 25

def resolved_proc
  ->(v) { v.respond_to?(:resolved) ? v.resolved : v }
end