Class: MarkdownRubyDocumentation::ClassLevelComment
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::ClassLevelComment
show all
- Includes:
- TemplateParser::Parsing
- Defined in:
- lib/markdown_ruby_documentation/class_level_comment.rb
Constant Summary
TemplateParser::Parsing::CLASS_MACROS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#extract_dsl_comment, #extract_dsl_comment_from_method, #get_line_number, #insert_method_name, #look_for_class_macro_comment, #parse_erb, #ruby_class_meth_comment, #ruby_class_meth_source_location, #source_location, #strip_comment_hash, #when_only_start, #when_start_and_end
Constructor Details
5
6
7
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 5
def initialize(subject)
@subject = subject
end
|
Instance Attribute Details
#subject ⇒ Object
Returns the value of attribute subject.
3
4
5
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 3
def subject
@subject
end
|
Instance Method Details
#call(interface) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 9
def call(interface)
_method = interface.reject do |_, meth|
meth[:method_object].is_a?(NullMethod) || meth[:method_object].visibility != :native
end.first
if _method
filename, lineno = _method[1][:method_object].to_proc.source_location
= (((filename, lineno)+"\n"))
interface[:class_level_comment] = { text: }
end
interface
end
|
21
22
23
24
25
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 21
def (filename, lineno)
method_to_top_of_file = File.read(filename).split("\n")[0..(lineno-1)]
subject_start_line = find_start_of_subject(method_to_top_of_file, filename)
(method_to_top_of_file[0..(subject_start_line-1)].reverse).reverse.join("\n")
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 38
def (lines)
buffer = []
lines.each do |line|
if line =~ /^\s*#/
buffer << line.lstrip
else
return buffer
end
end
buffer
end
|
#find_start_of_subject(method_to_top_of_file, filename) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/markdown_ruby_documentation/class_level_comment.rb', line 27
def find_start_of_subject(method_to_top_of_file, filename)
method_to_top_of_file.each_with_index do |line, index|
if line =~ /#{subject.class.to_s.downcase} #{subject.name.split("::").last}/
return index
end
end
puts /#{subject.class} #{subject.name.split("::").last}/
puts method_to_top_of_file
raise "class #{subject.name} not found in #{filename}"
end
|