Class: ActiveDoc::DescribedMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/active_doc/described_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, method_name, descriptions, origin) ⇒ DescribedMethod

Returns a new instance of DescribedMethod.



4
5
6
7
8
# File 'lib/active_doc/described_method.rb', line 4

def initialize(base, method_name, descriptions, origin)
  @base, @method_name, @descriptions = base, method_name, descriptions
  @origin_file, @origin_line = origin.split(":")
  @origin_line = @origin_line.to_i
end

Instance Attribute Details

#descriptionsObject (readonly)

Returns the value of attribute descriptions.



3
4
5
# File 'lib/active_doc/described_method.rb', line 3

def descriptions
  @descriptions
end

#origin_fileObject (readonly)

Returns the value of attribute origin_file.



3
4
5
# File 'lib/active_doc/described_method.rb', line 3

def origin_file
  @origin_file
end

#origin_lineObject (readonly)

Returns the value of attribute origin_line.



3
4
5
# File 'lib/active_doc/described_method.rb', line 3

def origin_line
  @origin_line
end

Instance Method Details

#to_rdocObject



10
11
12
13
14
# File 'lib/active_doc/described_method.rb', line 10

def to_rdoc
  rdoc_lines = descriptions.map {|x| x.to_rdoc.lines.map{ |l| "# #{l.chomp}" }}.flatten
  rdoc_lines.unshift("# ==== Attributes:")
  return rdoc_lines.join("\n") << "\n"
end

#write_rdoc(offset) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_doc/described_method.rb', line 16

def write_rdoc(offset)
  File.open(@origin_file, "r+") do |f|
    lines = f.readlines
    rdoc_lines = to_rdoc.lines.to_a
    rdoc_space_range = rdoc_space_range(offset)
    lines[rdoc_space_range] = rdoc_lines
    offset += rdoc_lines.size - rdoc_space_range.to_a.size
    f.pos = 0
    lines.each do |line|
      f.print line
    end
    f.truncate(f.pos)
  end
  return offset
end