Class: TestParser::SourceCode
Instance Attribute Summary
Attributes inherited from Snippet
#sexp
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Snippet
#get_block, #initialize, #to_code
Class Method Details
.clear_cache ⇒ Object
21
22
23
|
# File 'lib/test_parser/source_code.rb', line 21
def self.clear_cache
@source_codes = nil
end
|
.for(filename) ⇒ Object
25
26
27
|
# File 'lib/test_parser/source_code.rb', line 25
def self.for(filename)
source_codes[File.expand_path(filename)]
end
|
.source_codes ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/test_parser/source_code.rb', line 12
def self.source_codes
@source_codes ||= begin
parser = RubyParser.new
Hash.new do |h, k|
h[k] = new(parser.parse File.read(k))
end
end
end
|
Instance Method Details
39
40
41
42
43
44
45
46
47
|
# File 'lib/test_parser/source_code.rb', line 39
def (line_number)
code_sexp = find_method_call_with_block(line_number)
code_sexp ||= find_method_call_without_block(line_number)
raise NoCodeInLineError unless code_sexp
Snippet.new(code_sexp)
end
|
29
30
31
32
33
34
35
36
37
|
# File 'lib/test_parser/source_code.rb', line 29
def (name)
name = name.to_sym
definitions = sexp.enum_for(:each_of_type, :defn)
method_sexp = definitions.find {|def_sexp| def_sexp[1] == name }
raise NoMethodFoundError unless method_sexp
Snippet.new(method_sexp)
end
|