Class: SpecForge::Attribute::ResolvableStruct

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Resolvable
Defined in:
lib/spec_forge/attribute/resolvable_struct.rb

Overview

Wraps struct-like objects (Struct, Data, OpenStruct) to make them resolvable

Provides resolution capabilities for struct-like objects, allowing their values to be resolved recursively while maintaining the original struct type.

Instance Method Summary collapse

Methods included from Resolvable

#resolve_as_matcher_proc, #resolve_proc, #resolved_proc

Instance Method Details

#resolveStruct, ...

Returns the struct with all values resolved (not cached)

Returns:

  • (Struct, Data, OpenStruct)

    A new struct-like object with resolved values



38
39
40
41
# File 'lib/spec_forge/attribute/resolvable_struct.rb', line 38

def resolve
  hash = value.to_h.transform_values(&resolve_proc)
  to_structlike(hash)
end

#resolve_as_matcherRSpec::Matchers::BuiltIn::BaseMatcher

Converts the struct's values into RSpec matchers

Returns:

  • (RSpec::Matchers::BuiltIn::BaseMatcher)

    An RSpec matcher for the struct



48
49
50
51
# File 'lib/spec_forge/attribute/resolvable_struct.rb', line 48

def resolve_as_matcher
  result = value.to_h.transform_values(&resolve_as_matcher_proc)
  Attribute::Literal.new(result).resolve_as_matcher
end

#resolvedStruct, ...

Returns the struct with all values fully resolved and cached

Returns:

  • (Struct, Data, OpenStruct)

    A new struct-like object with resolved values



28
29
30
31
# File 'lib/spec_forge/attribute/resolvable_struct.rb', line 28

def resolved
  hash = value.to_h.transform_values(&resolved_proc)
  to_structlike(hash)
end

#valueStruct, ...

Returns the wrapped struct object

Returns:

  • (Struct, Data, OpenStruct)

    The underlying struct-like object



19
20
21
# File 'lib/spec_forge/attribute/resolvable_struct.rb', line 19

def value
  __getobj__
end