Class: RspecApiDocumentation::Writers::CombinedTextWriter

Inherits:
Writer
  • Object
show all
Defined in:
lib/rspec_api_documentation/writers/combined_text_writer.rb

Instance Attribute Summary

Attributes inherited from Writer

#configuration, #index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Writer

clear_docs, #initialize, write

Constructor Details

This class inherits a constructor from RspecApiDocumentation::Writers::Writer

Class Method Details

.format_hash(hash, separator = "=") ⇒ Object



32
33
34
35
36
# File 'lib/rspec_api_documentation/writers/combined_text_writer.rb', line 32

def self.format_hash(hash, separator="=")
  hash.sort_by { |k, v| k }.inject("") do |out, (k, v)|
    out << "  #{k}#{separator}#{v}\n"
  end
end

Instance Method Details

#writeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec_api_documentation/writers/combined_text_writer.rb', line 4

def write
  index.examples.each do |rspec_example|
    example = CombinedTextExample.new(rspec_example)
    FileUtils.mkdir_p(configuration.docs_dir.join(example.resource_name))
    File.open(configuration.docs_dir.join(example.resource_name, "index.txt"), "a+") do |f|
      f.print example.description
      f.print example.parameters

      example.requests.each_with_index do |(request, response), i|
        f.puts "Request:"
        f.puts request
        f.puts
        f.puts "Response:"
        f.puts response

        if i + 1 < example.requests.count
          f.puts
        end
      end

      unless rspec_example == index.examples.last
        f.puts
        f.puts
      end
    end
  end
end