Module: Oselvar::Var::Core::Registries
- Defined in:
- lib/oselvar/var/core/registry.rb
Class Method Summary collapse
-
.add_step(registry, expression:, expression_source_file:, expression_source_line:, handler:, kind: nil) ⇒ Object
Compile
expressionand append it. - .create_registry ⇒ Object
-
.define_parameter_type(registry, name:, regexp:, parse: nil, use_for_snippets: true, prefer_for_regexp_match: false, format: nil) ⇒ Object
Register a custom parameter type with the shared ParameterTypeRegistry (mutated in place, same as TS, so previously compiled expressions gain the new type).
Class Method Details
.add_step(registry, expression:, expression_source_file:, expression_source_line:, handler:, kind: nil) ⇒ Object
Compile expression and append it. Returns a new Registry (the
ParameterTypeRegistry is shared by reference but never mutated here).
Raises on duplicate expressions, mirroring the TS message.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/oselvar/var/core/registry.rb', line 35 def add_step(registry, expression:, expression_source_file:, expression_source_line:, handler:, kind: nil) duplicate = registry.steps.find { |s| s.expression == expression } if duplicate raise "duplicate step definition for \"#{expression}\" at " \ "#{duplicate.expression_source_file}:#{duplicate.expression_source_line} and " \ "#{expression_source_file}:#{expression_source_line}" end compiled = Cucumber::CucumberExpressions::CucumberExpression.new(expression, registry.parameter_types) reg = StepRegistration.new( expression: expression, expression_source_file: expression_source_file, expression_source_line: expression_source_line, handler: handler, compiled: compiled, kind: kind ) registry.with(steps: registry.steps + [reg]) end |
.create_registry ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/oselvar/var/core/registry.rb', line 24 def create_registry Registry.new( steps: [], parameter_types: Cucumber::CucumberExpressions::ParameterTypeRegistry.new, formats: {} ) end |
.define_parameter_type(registry, name:, regexp:, parse: nil, use_for_snippets: true, prefer_for_regexp_match: false, format: nil) ⇒ Object
Register a custom parameter type with the shared ParameterTypeRegistry
(mutated in place, same as TS, so previously compiled expressions gain
the new type). Returns the same Registry unless a format is given.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/oselvar/var/core/registry.rb', line 58 def define_parameter_type(registry, name:, regexp:, parse: nil, use_for_snippets: true, prefer_for_regexp_match: false, format: nil) regexps = regexp.is_a?(Array) ? regexp : [regexp] transformer = parse || ->(*groups) { groups[0] } # `type` is return-type metadata only (used by snippet generation, never # by matching, transformation, or any conformance artifact). The Ruby # gem rejects a nil type (Python's accepts None), so pass Object. pt = Cucumber::CucumberExpressions::ParameterType.new( name, regexps, Object, transformer, use_for_snippets, prefer_for_regexp_match ) registry.parameter_types.define_parameter_type(pt) return registry if format.nil? registry.with(formats: registry.formats.merge(name => format)) end |