module EmberGen::Support::FileSupport
Public Instance Methods
download(url)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/ember-gen/support/file_support.rb, line 8 def parse_name(path) path.match(%r~.*[/](?<name>.+)$~)[:name] end