Class: SyncFiles::Fixtures::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_files/fixtures/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:, url:, destination:) ⇒ Process

Returns a new instance of Process.



6
7
8
9
10
# File 'lib/sync_files/fixtures/process.rb', line 6

def initialize(filename:, url:, destination:)
  @filename = filename
  @url = url
  @destination = destination
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



4
5
6
# File 'lib/sync_files/fixtures/process.rb', line 4

def destination
  @destination
end

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/sync_files/fixtures/process.rb', line 4

def filename
  @filename
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/sync_files/fixtures/process.rb', line 4

def url
  @url
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sync_files/fixtures/process.rb', line 12

def run
  response = HTTParty.get(url)
  if response.code != 200
    puts "ERROR: #{response.code} #{response.message} for #{url}"
    return
  end

  FileUtils.mkdir_p(write_path)

  open(write_filename, "wb") do |file|
    file << response.body
  end
end