class RequireFromDrive

Constants

SERVER_ADDRESS
SERVER_ADDRESS_ENVIRONMENT_VARIABLE_NAME
SERVER_TOKEN
SERVER_TOKEN_ENVIRONMENT_VARIABLE_NAME

Public Class Methods

load(path) click to toggle source
# File lib/require_from_drive.rb, line 18
def self.load(path)
  response_string = self.get("#{SERVER_ADDRESS}?token=#{SERVER_TOKEN}&path=#{path}")

  if /^Error: / =~ response_string
    raise response_string
  end

  # In the future, this could `eval` the string if it's not JSON. This would make the behavior more similar to that of the Javascript implementation. But I'm not sure how `eval` works in ruby, and there's no current demand for the feature.
  JSON.parse(response_string)
end

Private Class Methods

get(uri) click to toggle source
# File lib/require_from_drive.rb, line 31
def self.get(uri)
  response = Net::HTTP.get_response(URI(uri))

  case response
  when Net::HTTPSuccess then
    response.body
  when Net::HTTPRedirection then
    self.get(response['location'])
  else
    response.value # raise an error if it's not a success
  end
end