Class: Servactory::TestKit::Rspec::Matchers::Base::SubmatcherContext
- Inherits:
-
Object
- Object
- Servactory::TestKit::Rspec::Matchers::Base::SubmatcherContext
- 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
-
#attribute_data ⇒ Hash
readonly
The attribute definition data from service info.
-
#attribute_name ⇒ Symbol
readonly
The name of the attribute being validated.
-
#attribute_type ⇒ Symbol
readonly
The attribute type (:input, :internal, :output).
-
#described_class ⇒ Class
readonly
The Servactory service class being tested.
-
#i18n_root_key ⇒ String?
readonly
The i18n root key for error messages.
-
#last_submatcher ⇒ Submatcher?
readonly
The previous submatcher for chained validations.
-
#option_types ⇒ Array?
readonly
Type classes from the .type() chain method.
Instance Method Summary collapse
-
#attribute_type_plural ⇒ Symbol
Returns the pluralized attribute type for accessing service info.
-
#initialize(described_class:, attribute_type:, attribute_name:, attribute_data:, option_types: nil, last_submatcher: nil, i18n_root_key: nil) ⇒ SubmatcherContext
constructor
Creates a new submatcher context.
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.
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_data ⇒ Hash (readonly)
Returns 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_name ⇒ Symbol (readonly)
Returns 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_type ⇒ Symbol (readonly)
Returns 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_class ⇒ Class (readonly)
Returns 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_key ⇒ String? (readonly)
Returns 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_submatcher ⇒ Submatcher? (readonly)
Returns 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_types ⇒ Array? (readonly)
Returns 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_plural ⇒ Symbol
Returns the pluralized attribute type for accessing service info.
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 |