Sha256: 7e493cd0becac64e12520df89e4cd0772d9d8d29754052bf0702edad996b9fa9

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module YARD::CodeObjects

  class StepTransformerObject < Base

    include Cucumber::LocationHelper

    attr_reader :constants, :keyword, :source, :value
    attr_accessor :steps

    ESCAPE_PATTERN = /#\{\s*(\w+)\s*\}/

    def value=(value)
      @value = format_source(value)

      until (nested = constants_from_value).empty?
        nested.each {|n| @value.gsub!(value_regex(n),find_value_for_constant(n)) }
      end
      
      @steps = []
    end

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

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

    protected

    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 an empty string for value." unless constant
      constant ? strip_regex_from(constant.value) : ""
    end
  
    def value_regex(value)
      /#\{\s*#{value}\s*\}/
    end

    def strip_regex_from(value)
      value.gsub(/^\/|\/$/,'')
    end


  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cucumber-in-the-yard-1.7.3 lib/yard/code_objects/step_transformer.rb
cucumber-in-the-yard-1.7.2 lib/yard/code_objects/step_transformer.rb
cucumber-in-the-yard-1.7.1 lib/yard/code_objects/step_transformer.rb
cucumber-in-the-yard-1.7.0 lib/yard/code_objects/step_transformer.rb
cucumber-in-the-yard-1.6.4 lib/yard/code_objects/step_transformer.rb
cucumber-in-the-yard-1.6.3 lib/yard/code_objects/step_transformer.rb