class YARD::CodeObjects::StepTransformerObject
Attributes
Public Instance Methods
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.
# 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
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.
# File lib/yard/code_objects/step_transformer.rb, line 16 def escape_pattern /#\{\s*(\w+)\s*\}/ end
Generate a regex with the step transform value.
# File lib/yard/code_objects/step_transformer.rb, line 53 def regex @regex ||= /#{strip_regex_from(value)}/ end
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 44 def value=(value) @literal_value = format_source(value) @value = format_source(value) @steps = [] value end
Protected Instance Methods
This looks through all the constants in the registry and returns the value with the regex items replaced from the constnat if present.
# File lib/yard/code_objects/step_transformer.rb, line 69 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 the regex starting / and ending / from the value.
# File lib/yard/code_objects/step_transformer.rb, line 81 def strip_regex_from(value) value.gsub(/^\/|\/$/,'') end
Return a regex of the value.
# File lib/yard/code_objects/step_transformer.rb, line 76 def value_regex(value) /#\{\s*#{value}\s*\}/ end