Skip to content

Commit

Permalink
Improved support for transforms assigned to variables. Constant's can…
Browse files Browse the repository at this point in the history
… now lonk to the transform and the docstring is passed to the transform
  • Loading branch information
Stephen-Kaye committed Jan 6, 2017
1 parent acfbfbb commit fa120b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/yard/handlers/constant_transform_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ class YARD::Handlers::Ruby::ConstantTransformHandler < YARD::Handlers::Ruby::Con
begin
if statement[1][0][0] == "Transform"
name = statement[0][0][0]
parse_block(statement[1])
# Move the docstring to the transform statement
statement[1].docstring = statement.docstring
# Set the docstring on the constant to reference the transform that will be processed
statement.docstring = "Reference to {#{YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE}::#{name} transform}"
value = statement[1][1].source
value = substitute(value)
value = convert_captures(strip_anchors(value))
register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value }
instance = register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value }
# specify the owner so that the transform can use the registered constant's name
parse_block(statement[1], {:owner => instance})

end
rescue
# This supresses any errors where any of the statement elements are out of bounds.
Expand Down
7 changes: 6 additions & 1 deletion lib/yard/handlers/step_transform_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def step_transform_namespace
end

def step_transformer_name
"step_transform#{self.class.generate_unique_id}"
# If the owner is a constant then we get the name of the constant so that the reference from the constant will work
if (owner.is_a?(YARD::CodeObjects::ConstantObject))
owner.name
else
"step_transform#{self.class.generate_unique_id}"
end
end

def self.generate_unique_id
Expand Down

0 comments on commit fa120b7

Please sign in to comment.