Module: Servactory::TestKit::Rspec::Matchers::Base::SubmatcherRegistry::ClassMethods
- Defined in:
- lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb
Overview
Class methods added to the including class.
Instance Method Summary collapse
-
#inherited(subclass) ⇒ void
Copies submatcher definitions to subclasses.
-
#register_submatcher(name, options = {}) ⇒ SubmatcherDefinition
Registers a new submatcher with configuration options.
-
#submatcher_definitions ⇒ Hash{Symbol => SubmatcherDefinition}
Returns the hash of registered submatcher definitions.
Instance Method Details
#inherited(subclass) ⇒ void
This method returns an undefined value.
Copies submatcher definitions to subclasses.
104 105 106 107 108 109 110 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 104 def inherited(subclass) super subclass.instance_variable_set( :@submatcher_definitions, submatcher_definitions.dup ) end |
#register_submatcher(name, options = {}) ⇒ SubmatcherDefinition
Registers a new submatcher with configuration options.
## Options
-
‘:class_name` - Relative class path (e.g., “Input::RequiredSubmatcher”)
-
‘:chain_method` - Method name for fluent API (defaults to name)
-
‘:chain_aliases` - Additional method names that call chain_method
-
‘:transform_args` - Lambda to transform method args before passing to submatcher
-
‘:requires_option_types` - Pass option_types to submatcher context
-
‘:requires_last_submatcher` - Pass previous submatcher to context
-
‘:mutually_exclusive_with` - Array of submatcher names to remove when this is added
-
‘:stores_option_types` - Store transformed args as option_types
-
‘:accepts_trailing_options` - Extract trailing hash as keyword arguments
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 85 def register_submatcher(name, = {}) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity submatcher_definitions[name] = SubmatcherDefinition.new( name:, class_name: [:class_name], chain_method: [:chain_method] || name, chain_aliases: [:chain_aliases] || [], transform_args: [:transform_args] || ->(args, _kwargs = {}) { args }, requires_option_types: [:requires_option_types] || false, requires_last_submatcher: [:requires_last_submatcher] || false, mutually_exclusive_with: [:mutually_exclusive_with] || [], stores_option_types: [:stores_option_types] || false, accepts_trailing_options: [:accepts_trailing_options] || false ) end |
#submatcher_definitions ⇒ Hash{Symbol => SubmatcherDefinition}
Returns the hash of registered submatcher definitions.
64 65 66 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 64 def submatcher_definitions @submatcher_definitions ||= {} end |