class YARD::CodeObjects::StepTransformerObject

Attributes

constants[R]
keyword[R]
literal_value[R]
pending[RW]
source[R]
steps[RW]
substeps[RW]
value[R]

Public Instance Methods

constants_from_value(data=@value) click to toggle source

Look through the specified data for the escape pattern and return an array of those constants found. This defaults to the @value within step transformer as it is used internally, however, it can be called externally if it's needed somewhere.

# File lib/yard/code_objects/step_transformer.rb, line 68
def constants_from_value(data=@value)
  data.scan(escape_pattern).flatten.collect { |value| value.strip }
end
escape_pattern() click to toggle source

This defines an escape pattern within a string or regex:

/^the first #{CONSTANT} step$/

This is used below in the value to process it if there happen to be constants defined here.

@note this does not handle the result of method calls @note this does not handle multiple constants within the same escaped area

# File lib/yard/code_objects/step_transformer.rb, line 18
def escape_pattern
  /#\{\s*(\w+)\s*\}/
end
regex() click to toggle source

Generate a regex with the step transformers value

# File lib/yard/code_objects/step_transformer.rb, line 60
def regex
  @regex ||= /#{strip_regex_from(value)}/
end
value=(value) click to toggle source

Set the literal value and the value of the step definition.

The literal value is as it appears in the step definition file with any constants. The value, when retrieved will attempt to replace those constants with their regex or string equivalents to hopefully match more steps and step definitions.

# File lib/yard/code_objects/step_transformer.rb, line 51
def value=(value)
  @literal_value = format_source(value)
  @value = format_source(value)

  @steps = []
  value
end

Protected Instance Methods

find_value_for_constant(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_transformer.rb, line 78
def find_value_for_constant(name)
  constant = YARD::Registry.all(:constant).find{|c| c.name == name.to_sym }
  log.warn "StepTransformer#find_value_for_constant : Could not find the CONSTANT [#{name}] using the string value." unless constant
  constant ? strip_regex_from(constant.value) : name
end
strip_regex_from(value) click to toggle source

Step the regex starting / and ending / from the value

# File lib/yard/code_objects/step_transformer.rb, line 90
def strip_regex_from(value)
  value.gsub(/^\/|\/$/,'')
end
value_regex(value) click to toggle source

Return a regex of the value

# File lib/yard/code_objects/step_transformer.rb, line 85
def value_regex(value)
  /#\{\s*#{value}\s*\}/
end