Class: CassetteRack::Drawer

Inherits:
Object
  • Object
show all
Defined in:
lib/cassette-rack/drawer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Drawer

Returns a new instance of Drawer.



10
11
12
# File 'lib/cassette-rack/drawer.rb', line 10

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/cassette-rack/drawer.rb', line 8

def name
  @name
end

Instance Method Details

#cassetteObject



14
15
16
# File 'lib/cassette-rack/drawer.rb', line 14

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

#deleteObject



22
23
24
# File 'lib/cassette-rack/drawer.rb', line 22

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

#exist?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cassette-rack/drawer.rb', line 26

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

#httpObject



38
39
40
# File 'lib/cassette-rack/drawer.rb', line 38

def http
  cassette.http_interactions.interactions.last
end

#pullObject



30
31
32
33
34
35
36
# File 'lib/cassette-rack/drawer.rb', line 30

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

#renderObject



18
19
20
# File 'lib/cassette-rack/drawer.rb', line 18

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