class RSpecApib::Parser

Transcludes and parses a api blueprint file

Attributes

base_element[RW]
document[RW]
index[RW]
parsed_file[RW]
transcluder[RW]

Public Class Methods

new(transcluder: Transcluder, base_element: Element::Base) click to toggle source
# File lib/rspec_apib/parser.rb, line 9
def initialize(transcluder: Transcluder, base_element: Element::Base)
  self.transcluder = transcluder
  self.base_element = base_element
end

Public Instance Methods

asset() click to toggle source
# File lib/rspec_apib/parser.rb, line 50
def asset
  index[Element::Asset]
end
categories() click to toggle source
# File lib/rspec_apib/parser.rb, line 26
def categories
  index[Element::Category]
end
copies() click to toggle source
# File lib/rspec_apib/parser.rb, line 30
def copies
  index[Element::Copy]
end
http_requests() click to toggle source
# File lib/rspec_apib/parser.rb, line 42
def http_requests
  index[Element::HttpRequest]
end
http_responses() click to toggle source
# File lib/rspec_apib/parser.rb, line 46
def http_responses
  index[Element::HttpResponse]
end
http_transactions() click to toggle source
# File lib/rspec_apib/parser.rb, line 38
def http_transactions
  index[Element::HttpTransaction]
end
parse_file(file) click to toggle source
# File lib/rspec_apib/parser.rb, line 14
def parse_file(file)
  self.parsed_file = decode_file(file)
  document, index = parse_document
  self.document = document
  self.index = index
  document
end
resources() click to toggle source
# File lib/rspec_apib/parser.rb, line 22
def resources
  index[Element::Resource]
end
transitions() click to toggle source
# File lib/rspec_apib/parser.rb, line 34
def transitions
  index[Element::Transition]
end

Private Instance Methods

bin_path() click to toggle source
# File lib/rspec_apib/parser.rb, line 62
def bin_path
  "drafter"
end
call_parser(file) click to toggle source
# File lib/rspec_apib/parser.rb, line 70
def call_parser(file)
  op = nil
  Open3.popen3("#{bin_path} -f json") do |stdin, stdout, _stderr, wait_thr|
    send_document(file: file, buffer: stdin)
    op = stdout.read
    wait_thr.value
  end
  op
end
decode_file(file) click to toggle source
# File lib/rspec_apib/parser.rb, line 66
def decode_file(file)
  JSON.parse call_parser(file)
end
parse_document() click to toggle source
# File lib/rspec_apib/parser.rb, line 58
def parse_document
  base_element.parse_root(parsed_file)
end
send_document(file:, buffer:) click to toggle source
# File lib/rspec_apib/parser.rb, line 80
def send_document(file:, buffer:)
  transcluder.each_line(file) do |line|
    buffer.write line
  end
  buffer.close
end