Class: YARD::CodeObjects::StepTransformerObject

Inherits:
Base
  • Object
show all
Includes:
Lucid::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 Lucid::LocationHelper

#file, #line_number, #location

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



6
7
8
# File 'lib/yard/code_objects/step_transformer.rb', line 6

def constants
  @constants
end

#keywordObject (readonly)

Returns the value of attribute keyword.



6
7
8
# File 'lib/yard/code_objects/step_transformer.rb', line 6

def keyword
  @keyword
end

#literal_valueObject (readonly)

Returns the value of attribute literal_value.



6
7
8
# File 'lib/yard/code_objects/step_transformer.rb', line 6

def literal_value
  @literal_value
end

#pendingObject

Returns the value of attribute pending.



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

def pending
  @pending
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/yard/code_objects/step_transformer.rb', line 6

def source
  @source
end

#stepsObject

Returns the value of attribute steps.



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

def steps
  @steps
end

#substepsObject

Returns the value of attribute substeps.



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

def substeps
  @substeps
end

#valueObject

The idea of this is method is that when requesting a step tranform object value, process it, if it hasn’t alredy been processed, replacing any constants that may be escaped within the value.

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



27
28
29
# File 'lib/yard/code_objects/step_transformer.rb', line 27

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 the step transform as it is used internally, however, it can be called externally if it’s needed somewhere.



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

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

#escape_patternObject

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. It’s important to note that this will not handle the result of method calls and it will not handle multiple constants within the same escaped area.



16
17
18
# File 'lib/yard/code_objects/step_transformer.rb', line 16

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

#regexObject

Generate a regex with the step transform value.



53
54
55
# File 'lib/yard/code_objects/step_transformer.rb', line 53

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