fetch_if_url 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8867c75036cc6f46f7c7bda62bb5ecfd45f992e10254e4fad9701f1b7b17d5cf
4
- data.tar.gz: df62c538f8c7eb765dc2cfc618b00481d2ddc5a72fcced431e1e1ed60ce6c993
3
+ metadata.gz: efcdaaaeeecbf080b39ce8e3c68c286125d5a36b1f1deeee8d312a3306936d80
4
+ data.tar.gz: ac77b081c564a522ccbf7f9bfb554d8768413c8f334d6f1baf3c5846c3894957
5
5
  SHA512:
6
- metadata.gz: c1260874488cfa160b2d5a0c71fd9f64e3c681d5aedf4a882b1632edc2c50d106a3c954b87258eb53e3c048062990b5cb11e0b6462ebdf858f830971a7af0961
7
- data.tar.gz: 48fc90f877974a0ef14cd6306a8f8eed52c3ff8d21cb58e3d0f28eba16dcf592c9ee3cdb2095e376ef2124c023ba4e0be53170d99ce029211c61a05475894360
6
+ metadata.gz: 66d7b418e4bcdad53d0257ce6ac63753814f23f6d847961e22d6be53372066141b3ed77f0c2b142f87f448c8f7893391888321b91aee314b66c233626d373b60
7
+ data.tar.gz: bb0f0854e4dff88b08ad5b4de1a708233a7ac3397ebe754205dd85bdc30b2550831bdd42cc07ff7fbf4dd1fd04974343aa16570d7093e1a4892b89d9c0986e48
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fetch_if_url (0.1.0)
4
+ fetch_if_url (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/fetch_if_url.svg)](https://badge.fury.io/rb/fetch_if_url)
1
2
  [![Build Status](https://travis-ci.com/oieioi/fetch_if_url.svg?branch=master)](https://travis-ci.com/oieioi/fetch_if_url)
2
3
 
3
4
  # FetchIfUrl
@@ -24,7 +25,7 @@ Or install it yourself as:
24
25
  ## Usage
25
26
 
26
27
  ```ruby
27
- CSV.foreach(fetch_if_url('https://example.org/some_heavy_csv.csv')) { |row| ... }
28
+ CSV.foreach(FetchIfUrl.fetch_if_url('https://example.org/some_heavy_csv.csv')) { |row| ... }
28
29
  ```
29
30
 
30
31
  ## Contributing
data/lib/fetch_if_url.rb CHANGED
@@ -7,26 +7,32 @@ require 'securerandom'
7
7
  module FetchIfUrl
8
8
  class Error < StandardError; end
9
9
 
10
+ # Fetch a file and return its temporary local path if <code>path</code> looks like URL.
11
+ # If it doesn't look like URL return as it be.
12
+ # @param [String] path file path or URL
13
+ # @param [Hash] opts
14
+ # @option opts [String] :dest Destination path when fetching
15
+ # @return [String] local path
10
16
  def fetch_if_url(path, dest: '/tmp')
11
- if on_network?(path)
12
- download(path, dest)
17
+ if url?(path)
18
+ fetch(path, dest)
13
19
  else
14
20
  # do nothing if local file
15
21
  path
16
22
  end
17
23
  end
18
24
 
19
- def on_network?(path)
25
+ def url?(path)
20
26
  path.start_with?(%r{https?://})
21
27
  end
22
28
 
23
- def download(url, dest)
29
+ def fetch(url, dest)
24
30
  body = Net::HTTP.get(URI.parse(url))
25
31
  file_name = "#{dest}/#{Time.now.to_i}-#{SecureRandom.uuid}"
26
32
  File.open(file_name, 'wb') { |file| file.write(body) }
27
33
  file_name
28
34
  end
29
35
 
30
- module_function :fetch_if_url, :on_network?, :download
31
- private_class_method :on_network?, :download
36
+ module_function :fetch_if_url, :url?, :fetch
37
+ private_class_method :url?, :fetch
32
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FetchIfUrl
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetch_if_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - oieioi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler