Class: Servactory::TestKit::Rspec::Matchers::Base::SubmatcherRegistry::SubmatcherDefinition

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

Overview

Value object holding configuration for a single submatcher registration.

## Purpose

Encapsulates all configuration options for a submatcher, including how to generate chain methods, transform arguments, and handle mutual exclusivity with other submatchers.

## Attributes

  • ‘name` - Unique identifier for this submatcher

  • ‘class_name` - Relative path to submatcher class

  • ‘chain_method` - Name of the fluent API method

  • ‘chain_aliases` - Alternative method names

  • ‘transform_args` - Lambda for argument transformation

  • ‘requires_option_types` - Whether submatcher needs type information

  • ‘requires_last_submatcher` - Whether submatcher needs previous submatcher

  • ‘mutually_exclusive_with` - Conflicting submatcher names

  • ‘stores_option_types` - Whether to store args as option_types

  • ‘accepts_trailing_options` - Whether to extract trailing hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, class_name:, chain_method: nil, chain_aliases: nil, transform_args: nil, requires_option_types: false, requires_last_submatcher: false, mutually_exclusive_with: nil, stores_option_types: false, accepts_trailing_options: false) ⇒ SubmatcherDefinition

Creates a new submatcher definition.

Parameters:

  • name (Symbol)

    Unique identifier

  • class_name (String)

    Relative class path

  • chain_method (Symbol) (defaults to: nil)

    Fluent API method name

  • chain_aliases (Array<Symbol>) (defaults to: nil)

    Alternative method names

  • transform_args (Proc) (defaults to: nil)

    Argument transformation lambda

  • requires_option_types (Boolean) (defaults to: false)

    Pass option_types to context

  • requires_last_submatcher (Boolean) (defaults to: false)

    Pass last_submatcher to context

  • mutually_exclusive_with (Array<Symbol>) (defaults to: nil)

    Conflicting submatchers

  • stores_option_types (Boolean) (defaults to: false)

    Store args as option_types

  • accepts_trailing_options (Boolean) (defaults to: false)

    Extract trailing hash



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 176

def initialize(
  name:,
  class_name:,
  chain_method: nil,
  chain_aliases: nil,
  transform_args: nil,
  requires_option_types: false,
  requires_last_submatcher: false,
  mutually_exclusive_with: nil,
  stores_option_types: false,
  accepts_trailing_options: false
)
  @name = name
  @class_name = class_name
  @chain_method = chain_method
  @chain_aliases = chain_aliases
  @transform_args = transform_args
  @requires_option_types = requires_option_types
  @requires_last_submatcher = requires_last_submatcher
  @mutually_exclusive_with = mutually_exclusive_with
  @stores_option_types = stores_option_types
  @accepts_trailing_options = accepts_trailing_options
end

Instance Attribute Details

#accepts_trailing_optionsBoolean (readonly)

Returns Whether to extract trailing hash as options.

Returns:

  • (Boolean)

    Whether to extract trailing hash as options



162
163
164
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 162

def accepts_trailing_options
  @accepts_trailing_options
end

#chain_aliasesArray<Symbol> (readonly)

Returns Alternative method names.

Returns:

  • (Array<Symbol>)

    Alternative method names



144
145
146
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 144

def chain_aliases
  @chain_aliases
end

#chain_methodSymbol (readonly)

Returns Method name for the fluent API.

Returns:

  • (Symbol)

    Method name for the fluent API



141
142
143
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 141

def chain_method
  @chain_method
end

#class_nameString (readonly)

Returns Relative class path (e.g., “Input::RequiredSubmatcher”).

Returns:

  • (String)

    Relative class path (e.g., “Input::RequiredSubmatcher”)



138
139
140
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 138

def class_name
  @class_name
end

#mutually_exclusive_withArray<Symbol> (readonly)

Returns Names of mutually exclusive submatchers.

Returns:

  • (Array<Symbol>)

    Names of mutually exclusive submatchers



156
157
158
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 156

def mutually_exclusive_with
  @mutually_exclusive_with
end

#nameSymbol (readonly)

Returns Unique identifier for this submatcher.

Returns:

  • (Symbol)

    Unique identifier for this submatcher



135
136
137
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 135

def name
  @name
end

#requires_last_submatcherBoolean (readonly)

Returns Whether submatcher needs last_submatcher in context.

Returns:

  • (Boolean)

    Whether submatcher needs last_submatcher in context



153
154
155
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 153

def requires_last_submatcher
  @requires_last_submatcher
end

#requires_option_typesBoolean (readonly)

Returns Whether submatcher needs option_types in context.

Returns:

  • (Boolean)

    Whether submatcher needs option_types in context



150
151
152
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 150

def requires_option_types
  @requires_option_types
end

#stores_option_typesBoolean (readonly)

Returns Whether to store transformed args as option_types.

Returns:

  • (Boolean)

    Whether to store transformed args as option_types



159
160
161
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 159

def stores_option_types
  @stores_option_types
end

#transform_argsProc (readonly)

Returns Lambda to transform arguments.

Returns:

  • (Proc)

    Lambda to transform arguments



147
148
149
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 147

def transform_args
  @transform_args
end