Sha256: e843985b3040cf9767bd0e2ae7f223e20340106b8c9226eb0ecd65da34152dfd

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

require 'kramdown'
require_relative 'decorator/request'
require_relative 'decorator/response'

module CassetteRack
  class Drawer
    attr_reader :name

    def initialize(name, options={})
      @name = name
    end

    def cassette
      @cassette ||= VCR::Cassette.new(name)
    end

    def render
      Kramdown::Document.new(self.pull).to_html
    end

    def delete
      File.delete cassette.file if self.exist?
    end

    def exist?
      File.exist?(cassette.file)
    end

    def pull
      request = CassetteRack::Decorator::Request.new(http.request)
      response = CassetteRack::Decorator::Response.new(http.response)

      template = Liquid::Template.parse(CassetteRack::Configure.content_template)
      template.render('title' => name, 'request' => request, 'response' => response)
    end

    def http
      cassette.http_interactions.interactions.last
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cassette-rack-0.10.0 lib/cassette-rack/drawer.rb
cassette-rack-0.9.0 lib/cassette-rack/drawer.rb
cassette-rack-0.8.1 lib/cassette-rack/drawer.rb
cassette-rack-0.8.0 lib/cassette-rack/drawer.rb