Class: Pears::Provider::RemoteFile

Inherits:
Base
  • Object
show all
Defined in:
lib/pears/provider/remote_file.rb

Overview

Fetch a yaml file via HTTP

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#[], #each, #has_key?, #purge

Constructor Details

#initialize(remote_url, on_failure: :raise) ⇒ RemoteFile

Returns a new instance of RemoteFile.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pears/provider/remote_file.rb', line 7

def initialize(remote_url, on_failure: :raise)
  yaml_data = Net::HTTP.get(URI(remote_url))
  @data = parse_yaml(yaml_data)

rescue SocketError,
    InvalidProviderData,
    Errno::ECONNREFUSED,
    Errno::EHOSTUNREACH,
    Errno::EADDRNOTAVAIL,
    Net::OpenTimeout => e
  if on_failure == :null
    @data = {}
  else
    raise e
  end
end