Class: CheckList::HandleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/handle_file.rb

Overview

Displays the keyword/method provided

Instance Method Summary collapse

Constructor Details

#initializeHandleFile

Returns a new instance of HandleFile.



10
11
12
13
# File 'lib/handle_file.rb', line 10

def initialize
  @default_file = nil
  fetch_default_file
end

Instance Method Details

#fetch_default_fileObject



15
16
17
18
19
20
# File 'lib/handle_file.rb', line 15

def fetch_default_file
  uri = URI.parse(CheckList::Config.default_url)
  @default_file = Net::HTTP.get_response(uri)
rescue StandardError
  @default_file = nil
end

#fetch_json(env_key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/handle_file.rb', line 22

def fetch_json(env_key)
  url = './checklist/data.json'
  url = ENV.fetch(env_key) if CheckList::Config.env == env_key
  JSON.parse(File.read(url))
rescue StandardError => e
  if env_key == CheckList::Config.env && !@default_file.nil?
    JSON.parse(@default_file.body)
  else
    CheckList::Helpers.log "Invalid file: #{e}"
    CheckList::Helpers.leave
  end
end