Class: Servactory::TestKit::Rspec::Matchers::Base::SubmatcherContext

Inherits:
Object
  • Object
show all
Defined in:
lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb

Overview

Data transfer object carrying context for submatcher validation.

## Purpose

SubmatcherContext encapsulates all the information a submatcher needs to perform its validation. It provides a clean interface for passing attribute metadata, service class info, and dependent data between the parent matcher and individual submatchers.

## Usage

Created by AttributeMatcher and passed to each submatcher:

“‘ruby context = SubmatcherContext.new(

described_class: MyService,
attribute_type: :input,
attribute_name: :user_id,
attribute_data: { type: Integer, required: true }

)

submatcher = RequiredSubmatcher.new(context) “‘

## Attributes

  • ‘described_class` - The Servactory service class being tested

  • ‘attribute_type` - :input, :internal, or :output

  • ‘attribute_name` - Name of the attribute being validated

  • ‘attribute_data` - Hash with attribute definition (type, required, etc.)

  • ‘option_types` - Type classes passed via .type() chain method

  • ‘last_submatcher` - Previous submatcher (for dependent validations)

  • ‘i18n_root_key` - Root key for i18n error messages

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(described_class:, attribute_type:, attribute_name:, attribute_data:, option_types: nil, last_submatcher: nil, i18n_root_key: nil) ⇒ SubmatcherContext

Creates a new submatcher context.

Parameters:

  • described_class (Class)

    The Servactory service class

  • attribute_type (Symbol)

    The attribute type (:input, :internal, :output)

  • attribute_name (Symbol)

    The attribute name

  • attribute_data (Hash)

    The attribute definition data

  • option_types (Array, nil) (defaults to: nil)

    Type classes from .type() method

  • last_submatcher (Submatcher, nil) (defaults to: nil)

    Previous submatcher for chaining

  • i18n_root_key (String, nil) (defaults to: nil)

    Root key for i18n messages



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 72

def initialize(
  described_class:,
  attribute_type:,
  attribute_name:,
  attribute_data:,
  option_types: nil,
  last_submatcher: nil,
  i18n_root_key: nil
)
  @described_class = described_class
  @attribute_type = attribute_type
  @attribute_name = attribute_name
  @attribute_data = attribute_data
  @option_types = option_types
  @last_submatcher = last_submatcher
  @i18n_root_key = i18n_root_key
end

Instance Attribute Details

#attribute_dataHash (readonly)

Returns The attribute definition data from service info.

Returns:

  • (Hash)

    The attribute definition data from service info



52
53
54
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 52

def attribute_data
  @attribute_data
end

#attribute_nameSymbol (readonly)

Returns The name of the attribute being validated.

Returns:

  • (Symbol)

    The name of the attribute being validated



49
50
51
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 49

def attribute_name
  @attribute_name
end

#attribute_typeSymbol (readonly)

Returns The attribute type (:input, :internal, :output).

Returns:

  • (Symbol)

    The attribute type (:input, :internal, :output)



46
47
48
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 46

def attribute_type
  @attribute_type
end

#described_classClass (readonly)

Returns The Servactory service class being tested.

Returns:

  • (Class)

    The Servactory service class being tested



43
44
45
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 43

def described_class
  @described_class
end

#i18n_root_keyString? (readonly)

Returns The i18n root key for error messages.

Returns:

  • (String, nil)

    The i18n root key for error messages



61
62
63
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 61

def i18n_root_key
  @i18n_root_key
end

#last_submatcherSubmatcher? (readonly)

Returns The previous submatcher for chained validations.

Returns:

  • (Submatcher, nil)

    The previous submatcher for chained validations



58
59
60
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 58

def last_submatcher
  @last_submatcher
end

#option_typesArray? (readonly)

Returns Type classes from the .type() chain method.

Returns:

  • (Array, nil)

    Type classes from the .type() chain method



55
56
57
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 55

def option_types
  @option_types
end

Instance Method Details

#attribute_type_pluralSymbol

Returns the pluralized attribute type for accessing service info.

Returns:

  • (Symbol)

    Pluralized type (:inputs, :internals, :outputs)



93
94
95
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb', line 93

def attribute_type_plural
  @attribute_type_plural ||= attribute_type.to_s.pluralize.to_sym
end