Class: RSpecDescribeHandler

Inherits:
YARD::Handlers::Ruby::Base
  • Object
show all
Defined in:
lib/yard-examples-from-rspec.rb

Overview

Handler used to inspect the rspec describe call used, to catch the class describe declarations and method declarations

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.current_classObject

Returns the value of attribute current_class.



35
36
37
# File 'lib/yard-examples-from-rspec.rb', line 35

def current_class
  @current_class
end

.current_methodObject

Returns the value of attribute current_method.



35
36
37
# File 'lib/yard-examples-from-rspec.rb', line 35

def current_method
  @current_method
end

Class Method Details

.current_pathObject



37
38
39
# File 'lib/yard-examples-from-rspec.rb', line 37

def current_path
  return "#{@current_class}##{@current_method}"
end

Instance Method Details

#processObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/yard-examples-from-rspec.rb', line 45

def process
  param = statement.parameters.first

  # A class is being declared
  if param.type == :var_ref && param.children.first.type == :const
    self.class.current_class = param.children.first.source  
  end

  # A class is being declared (with a nested name)
  if param.type == :const_path_ref 
    self.class.current_class = param.children.map{|i| i.source}.join("::")
  end

  # A method is being declared
  if param.type == :string_literal && param.source =~ /^"#/      
    self.class.current_method = param.source.delete('#|"|\ ')
  end

  parse_block(statement.last.last)
end