Class: YARD::CodeObjects::StepTransformerObject

Inherits:
Base
  • Object
show all
Includes:
Cucumber::LocationHelper
Defined in:
lib/yard/code_objects/step_transformer.rb

Direct Known Subclasses

StepDefinitionObject, StepTransformObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cucumber::LocationHelper

#file, #line_number, #location

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



8
9
10
# File 'lib/yard/code_objects/step_transformer.rb', line 8

def constants
  @constants
end

#keywordObject (readonly)

Returns the value of attribute keyword.



8
9
10
# File 'lib/yard/code_objects/step_transformer.rb', line 8

def keyword
  @keyword
end

#literal_valueObject (readonly)

Returns the value of attribute literal_value.



8
9
10
# File 'lib/yard/code_objects/step_transformer.rb', line 8

def literal_value
  @literal_value
end

#pendingObject

Returns the value of attribute pending.



9
10
11
# File 'lib/yard/code_objects/step_transformer.rb', line 9

def pending
  @pending
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/yard/code_objects/step_transformer.rb', line 8

def source
  @source
end

#stepsObject

Returns the value of attribute steps.



9
10
11
# File 'lib/yard/code_objects/step_transformer.rb', line 9

def steps
  @steps
end

#substepsObject

Returns the value of attribute substeps.



9
10
11
# File 'lib/yard/code_objects/step_transformer.rb', line 9

def substeps
  @substeps
end

#valueObject

When requesting a step tranformer object value, process it, if it hasn’t alredy been processed, replacing any constants that may be lurking within the value.

Processing it means looking for any escaped characters that happen to be CONSTANTS that could be matched and then replaced. This is done recursively as CONSTANTS can be defined with more CONSTANTS.



33
34
35
# File 'lib/yard/code_objects/step_transformer.rb', line 33

def value
  @value
end

Instance Method Details

#constants_from_value(data = @value) ⇒ Object

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.



70
71
72
# File 'lib/yard/code_objects/step_transformer.rb', line 70

def constants_from_value(data=@value)
  data.scan(escape_pattern).flatten.collect { |value| value.strip }
end

#escape_patternObject

Note:

this does not handle the result of method calls

Note:

this does not handle multiple constants within the same escaped area

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.



20
21
22
# File 'lib/yard/code_objects/step_transformer.rb', line 20

def escape_pattern
  /#\{\s*(\w+)\s*\}/
end

#regexObject

Generate a regex with the step transformers value



62
63
64
# File 'lib/yard/code_objects/step_transformer.rb', line 62

def regex
  @regex ||= /#{strip_regex_from(value)}/
end