class YARD::CodeObjects::StepDefinition

Constants

ALTERNATIVE_WORD_REGEXP
OPTIONAL_WORD_REGEXP
PLACEHOLDER_REGEXP

Attributes

placeholders[RW]

Public Instance Methods

value() click to toggle source
# File lib/yard/code_objects/step_definition.rb, line 10
def value
  unless @processed
    @placeholders = []
    @processed = true
    @value = Regexp.escape(@value)
    @value.gsub!(PLACEHOLDER_REGEXP) do |_|
      find_value_for_placeholder($1)
    end
    @value.gsub!(OPTIONAL_WORD_REGEXP) do |_|
      [$1, $2, $3].compact.map { |m| "(?:#{m})?" }.join
    end
    @value.gsub!(ALTERNATIVE_WORD_REGEXP) do |_|
      "(?:#{$1}#{$2.tr('/', '|')})"
    end
  end
  @value
end

Private Instance Methods

find_value_for_placeholder(name) click to toggle source

Looking through all the constants in the registry and returning the value with the regex items replaced from the constnat if present

# File lib/yard/code_objects/step_definition.rb, line 35
def find_value_for_placeholder(name)
  placeholder_matches = YARD::Registry.all(:placeholder).select{ |p|  p.literal_value == name }
  regex = if placeholder_matches.empty?
    YARD::CodeObjects::Placeholder::DEFAULT_PLACE_HOLDER_REGEXP_STRING
  else
    placeholders.push(*placeholder_matches)
    placeholder_matches.map(&:regex).join('|')
  end
  "(?<placeholder_#{name[1..-1]}>#{regex})"
end