Class: Rack::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/capture.rb,
lib/rack/capture/version.rb

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app:, url:, output_directory_path: 'output', script_name: '') ⇒ Capture

Returns a new instance of Capture.

Parameters:

  • app (#call)

    Rack application.

  • output_directory_path (String) (defaults to: 'output')
  • script_name (String) (defaults to: '')
  • url (String)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/capture.rb', line 19

def initialize(
  app:,
  url:,
  output_directory_path: 'output',
  script_name: ''
)
  @app = app
  @output_directory_path = output_directory_path
  @script_name = script_name
  @url = url
end

Class Method Details

.call(**args) ⇒ Object



10
11
12
# File 'lib/rack/capture.rb', line 10

def call(**args)
  new(**args).call
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/rack/capture.rb', line 31

def call
  response = get_response
  destination = calculate_destination(response: response)
  destination.parent.mkpath
  content = ''
  response.body.each do |element|
    content += element
  end
  destination.write(content)
end