Sha256: 820163860dde1ed452ecead741b2f118bb297dad9d5a661ba935b7cde474d35f

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

class YARD::Handlers::Ruby::StepTransformHandler < YARD::Handlers::Ruby::Base
  handles method_call(:Transform)
  handles method_call(:ParameterType)

  process do

    nextStatement = nil
    instance = YARD::CodeObjects::StepTransformObject.new(step_transform_namespace,step_transformer_name) do |o|
      o.source = statement.source
      o.comments = statement.comments
      o.keyword = statement[0].source
      if (o.keyword == 'Transform')
        o.value = statement[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
        nextStatement = statement[2]
      elsif (o.keyword == 'ParameterType')
        o.value = find(statement, :label, 'regexp:').parent.children[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
        nextStatement = find(statement, :label, 'transformer:').parent.children[1]
      end
    end

    obj = register instance
    parse_block(nextStatement,:owner => obj)

  end

  def step_transform_namespace
    YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
  end

  def step_transformer_name
    # 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
    @step_transformer_count = @step_transformer_count.to_i + 1
  end

  private

  def find(node, node_type, value)
    node.traverse { |child| return(child) if node_type == child.type && child.source == value }
    self
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
yard-nrser-cucumber-0.1.3 lib/yard/handlers/step_transform_handler.rb
yard-nrser-cucumber-0.1.2 lib/yard/handlers/step_transform_handler.rb
yard-nrser-cucumber-0.1.1 lib/yard/handlers/step_transform_handler.rb
yard-nrser-cucumber-0.1.0 lib/yard/handlers/step_transform_handler.rb
yard-cucumber-4.0.0 lib/yard/handlers/step_transform_handler.rb