Module: EmberGen::Support::FileSupport

Defined in:
lib/ember-gen/support/file_support.rb

Instance Method Summary collapse

Instance Method Details

#download(url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/ember-gen/support/file_support.rb', line 20

def download(url)
  begin
    puts "Downloading: #{url}"
    tmp_file = open(url)
    puts "downloaded #{tmp_file.size / 1024}KB"
    tmp_file
  rescue OpenURI::HTTPError
    puts "Download failed: #{url}"
  end
end

#download_and_move(url, destination) ⇒ Object



31
32
33
34
# File 'lib/ember-gen/support/file_support.rb', line 31

def download_and_move(url, destination)
  tmp_file = download(url)
  File.rename tmp_file, destination
end

#github_url_to_raw(url) ⇒ Object



36
37
38
# File 'lib/ember-gen/support/file_support.rb', line 36

def github_url_to_raw(url)
  url.sub("https://", "https://raw2.").sub('blob/', '')
end

#grab_json(url) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ember-gen/support/file_support.rb', line 12

def grab_json(url)
  begin
    JSON.parse(download(url).read)
  rescue
    puts "There was a problem fetching y'r JSON"
  end
end

#parse_name(path) ⇒ Object



8
9
10
# File 'lib/ember-gen/support/file_support.rb', line 8

def parse_name(path)
  path.match(%r~.*[/](?<name>.+)$~)[:name]
end