Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [JavaScript] Added TypeScript source to the package ([#211](https://github.com/cucumber/cucumber-expressions/pull/211))
- [Ruby] Minimum supported ruby is now 2.5+ ([#232](https://github.com/cucumber/cucumber-expressions/pull/232))
- [Ruby] Large suite wide refactor for basic rubocop compliance ([#233](https://github.com/cucumber/cucumber-expressions/pull/233))
- [Ruby] Change public API readers for `ParameterType`
- Expose `transformer` arg as a public reader
- Remove `prefer_for_regexp_match?` and `use_for_snippets?` -> Use their reader equivalents instead (Remove the `?`)
([#234](https://github.com/cucumber/cucumber-expressions/pull/234))

## [16.1.2] - 2023-01-17
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def generate_expressions(text)
def create_parameter_type_matchers(text)
parameter_matchers = []
@parameter_type_registry.parameter_types.each do |parameter_type|
parameter_matchers += create_parameter_type_matchers2(parameter_type, text) if parameter_type.use_for_snippets?
parameter_matchers += create_parameter_type_matchers2(parameter_type, text) if parameter_type.use_for_snippets
end
parameter_matchers
end
Expand Down
21 changes: 6 additions & 15 deletions ruby/lib/cucumber/cucumber_expressions/parameter_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ParameterType
ILLEGAL_PARAMETER_NAME_PATTERN = /([\[\]()$.|?*+])/.freeze
UNESCAPE_PATTERN = /(\\([\[$.|?*+\]]))/.freeze

attr_reader :name, :type, :regexps
attr_reader :name, :type, :transformer, :use_for_snippets, :prefer_for_regexp_match, :regexps

def self.check_parameter_type_name(type_name)
raise CucumberExpressionError.new("Illegal character in parameter name {#{type_name}}. Parameter names may not contain '[]()$.|?*+'") unless is_valid_parameter_type_name(type_name)
Expand All @@ -21,14 +21,6 @@ def self.is_valid_parameter_type_name(type_name)
!(ILLEGAL_PARAMETER_NAME_PATTERN =~ unescaped_type_name)
end

def prefer_for_regexp_match?
@prefer_for_regexp_match
end

def use_for_snippets?
@use_for_snippets
end

# Create a new Parameter
#
# @param name the name of the parameter type
Expand All @@ -55,24 +47,23 @@ def transform(self_obj, group_values)
end

def <=>(other)
return -1 if prefer_for_regexp_match? && !other.prefer_for_regexp_match?
return 1 if other.prefer_for_regexp_match? && !prefer_for_regexp_match?
return -1 if prefer_for_regexp_match && !other.prefer_for_regexp_match
return 1 if other.prefer_for_regexp_match && !prefer_for_regexp_match
return name <=> other.name
end

private


def string_array(regexps)
array = regexps.is_a?(Array) ? regexps : [regexps]
array.map { |regexp| regexp.is_a?(String) ? regexp : regexp_source(regexp) }
end

def regexp_source(regexp)
[
'EXTENDED',
'IGNORECASE',
'MULTILINE'
'EXTENDED',
'IGNORECASE',
'MULTILINE'
].each do |option_name|
option = Regexp.const_get(option_name)
raise CucumberExpressionError.new("ParameterType Regexps can't use option Regexp::#{option_name}") if regexp.options & option != 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def lookup_by_type_name(name)
def lookup_by_regexp(parameter_type_regexp, expression_regexp, text)
parameter_types = @parameter_types_by_regexp[parameter_type_regexp]
return nil if parameter_types.nil?
if parameter_types.length > 1 && !parameter_types[0].prefer_for_regexp_match?
if parameter_types.length > 1 && !parameter_types[0].prefer_for_regexp_match
# We don't do this check on insertion because we only want to restrict
# ambiguity when we look up by Regexp. Users of CucumberExpression should
# not be restricted.
Expand Down Expand Up @@ -66,7 +66,7 @@ def define_parameter_type(parameter_type)

parameter_type.regexps.each do |parameter_type_regexp|
parameter_types = @parameter_types_by_regexp[parameter_type_regexp]
if parameter_types.any? && parameter_types[0].prefer_for_regexp_match? && parameter_type.prefer_for_regexp_match?
if parameter_types.any? && parameter_types[0].prefer_for_regexp_match && parameter_type.prefer_for_regexp_match
raise CucumberExpressionError.new("There can only be one preferential parameter type per regexp. The regexp /#{parameter_type_regexp}/ is used for two preferential parameter types, {#{parameter_types[0].name}} and {#{parameter_type.name}}")
end
parameter_types.push(parameter_type)
Expand Down