Class: Pangea::Testing::MockResourceReference

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/testing/mock_resource_reference.rb

Overview

Mock resource reference for testing. Returns Terraform-style interpolation strings for attribute access (e.g., “$aws_vpcaws_vpc.mainaws_vpc.main.id”).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, attributes = {}) ⇒ MockResourceReference

Returns a new instance of MockResourceReference.



24
25
26
27
28
# File 'lib/pangea/testing/mock_resource_reference.rb', line 24

def initialize(type, name, attributes = {})
  @type = type
  @name = name
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args, &_block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/pangea/testing/mock_resource_reference.rb', line 54

def method_missing(method_name, *_args, &_block)
  # Check both string and symbol key access
  if @attributes.key?(method_name)
    @attributes[method_name]
  elsif @attributes.key?(method_name.to_s)
    @attributes[method_name.to_s]
  else
    "${#{@type}.#{@name}.#{method_name}}"
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



22
23
24
# File 'lib/pangea/testing/mock_resource_reference.rb', line 22

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/pangea/testing/mock_resource_reference.rb', line 22

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/pangea/testing/mock_resource_reference.rb', line 22

def type
  @type
end

Instance Method Details

#arnObject



34
35
36
# File 'lib/pangea/testing/mock_resource_reference.rb', line 34

def arn
  "${#{@type}.#{@name}.arn}"
end

#emailObject



38
39
40
# File 'lib/pangea/testing/mock_resource_reference.rb', line 38

def email
  "${#{@type}.#{@name}.email}"
end

#endpointObject



42
43
44
# File 'lib/pangea/testing/mock_resource_reference.rb', line 42

def endpoint
  "${#{@type}.#{@name}.endpoint}"
end

#idObject



30
31
32
# File 'lib/pangea/testing/mock_resource_reference.rb', line 30

def id
  "${#{@type}.#{@name}.id}"
end

#ipv4_addressObject



46
47
48
# File 'lib/pangea/testing/mock_resource_reference.rb', line 46

def ipv4_address
  "${#{@type}.#{@name}.ipv4_address}"
end

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/pangea/testing/mock_resource_reference.rb', line 65

def respond_to_missing?(_method_name, _include_private = false)
  true
end

#to_hObject



50
51
52
# File 'lib/pangea/testing/mock_resource_reference.rb', line 50

def to_h
  { type: @type, name: @name, attributes: @attributes }
end