carrierwave-google-storage 0.7.0 → 0.8.0

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
  SHA1:
3
- metadata.gz: d74ba19cc3e6aeb961c24c00e923e9c5dc4042c0
4
- data.tar.gz: 068e42fe00e040c66ca5968b415aed0d53c4434d
3
+ metadata.gz: b5dfca5548a4c471cf6e394371707876c087c8ca
4
+ data.tar.gz: 499ef7b488e98cbc81cbb79a3267ffac4e4fd360
5
5
  SHA512:
6
- metadata.gz: 43827bbf9a6a6963215dda5a39189671b0d2d0536dd57d66616285151caaacfb858e40e9d0a9d9c9e9021ef10e664e5e9f8c1fde77fc61089f5659f01aef6d5f
7
- data.tar.gz: 305c284173189a29f1c51c794fe74634482d3918f8078e2530aa7378eba1615d318b56c60454c64cac241fc490270a9c4a45637b47f18ce76d9636bae041783e
6
+ metadata.gz: b5696f16b95a947270b694f626f7eebd2664b1c9148ec3646eb64705127ae089d9d6815fecda973abd7498b13bde0e4e958d45d356547dd2618e809eb12bba3f
7
+ data.tar.gz: 4bbfb4067e0e012b6ad017ae76906990b8f71bccf4d7402bcae25f24f05432122cc9a752a2b5dbb599d9a2e0b3edd7ac3bff232447a2790148d84b66f09e3465
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
4
  - 2.1.0
6
5
  - 2.2.0
7
6
  - 2.3.0
7
+ - 2.4.1
8
8
  before_install:
9
9
  - openssl aes-256-cbc -K $encrypted_121e786cd5aa_key -iv $encrypted_121e786cd5aa_iv -in .gcp-keyfile.json.enc -out .gcp-keyfile.json -d
10
10
  - gem install bundler -v 1.12.1
@@ -1,35 +1,36 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'carrierwave/google/storage/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "carrierwave-google-storage"
8
+ spec.name = 'carrierwave-google-storage'
8
9
  spec.version = Carrierwave::Google::Storage::VERSION
9
- spec.authors = ["Jasdeep Singh"]
10
- spec.email = ["narang.jasdeep@gmail.com"]
10
+ spec.authors = ['Jasdeep Singh']
11
+ spec.email = ['narang.jasdeep@gmail.com']
11
12
 
12
- spec.summary = %q{Use gcloud for Google Cloud Storage support in CarrierWave.}
13
- spec.description = %q{A slimmer alternative to using Fog for Google Cloud Storage support in CarrierWave. Heavily inspired from carrierwave-aws}
14
- spec.homepage = "https://github.com/metaware/carrierwave-google-storage"
15
- spec.license = "MIT"
13
+ spec.summary = %q(Use gcloud for Google Cloud Storage support in CarrierWave.)
14
+ spec.description = %q(A slimmer alternative to using Fog for Google Cloud Storage support in CarrierWave. Heavily inspired from carrierwave-aws)
15
+ spec.homepage = 'https://github.com/metaware/carrierwave-google-storage'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_dependency 'google-cloud-storage', '~> 0.21.0'
23
- spec.add_dependency 'carrierwave', '~> 0.11.2'
24
- if RUBY_VERSION >= "2.2.2"
25
- spec.add_dependency 'activemodel', ">= 3.2.0"
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'carrierwave', '~> 1.2.0'
24
+ spec.add_dependency 'google-cloud-storage', '~> 1.9.0'
25
+ if RUBY_VERSION >= '2.2.2'
26
+ spec.add_dependency 'activemodel', '>= 3.2.0'
26
27
  else
27
- spec.add_dependency 'activemodel', "~> 4.2.7"
28
+ spec.add_dependency 'activemodel', '~> 4.2.7'
28
29
  end
29
30
 
30
- spec.add_development_dependency "bundler", "~> 1.12"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "pry", "~> 0.10.3"
34
- spec.add_development_dependency "uri-query_params", "~> 0.7.1"
31
+ spec.add_development_dependency 'bundler', '~> 1.12'
32
+ spec.add_development_dependency 'pry', '~> 0.10.3'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'uri-query_params', '~> 0.7.1'
35
36
  end
@@ -6,18 +6,21 @@ require 'carrierwave/storage/gcloud_file'
6
6
  require 'carrierwave/storage/gcloud_options'
7
7
  require 'carrierwave/support/uri_filename'
8
8
 
9
- class CarrierWave::Uploader::Base
10
-
11
- ConfigurationError = Class.new(StandardError)
9
+ module CarrierWave
10
+ module Uploader
11
+ class Base
12
12
 
13
- add_config :gcloud_attributes
14
- add_config :gcloud_bucket
15
- add_config :gcloud_bucket_is_public
16
- add_config :gcloud_credentials
17
- add_config :gcloud_authenticated_url_expiration
13
+ ConfigurationError = Class.new(StandardError)
18
14
 
19
- configure do |config|
20
- config.storage_engines[:gcloud] = 'CarrierWave::Storage::Gcloud'
21
- end
15
+ add_config :gcloud_attributes
16
+ add_config :gcloud_bucket
17
+ add_config :gcloud_bucket_is_public
18
+ add_config :gcloud_credentials
19
+ add_config :gcloud_authenticated_url_expiration
22
20
 
23
- end
21
+ configure do |config|
22
+ config.storage_engines[:gcloud] = 'CarrierWave::Storage::Gcloud'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Carrierwave
2
4
  module Google
3
5
  module Storage
4
- VERSION = "0.7.0"
6
+ VERSION = '0.8.0'.freeze
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CarrierWave
2
4
  module Storage
3
5
  class Gcloud < Abstract
4
-
5
6
  def self.connection_cache
6
7
  @connection_cache ||= {}
7
8
  end
@@ -9,28 +10,54 @@ module CarrierWave
9
10
  def self.clear_connection_cache!
10
11
  @connection_cache = {}
11
12
  end
12
-
13
+
13
14
  def store!(file)
14
- CarrierWave::Storage::GcloudFile.new(uploader, connection, uploader.store_path).tap do |gcloud_file|
15
+ GcloudFile.new(uploader, connection, uploader.store_path).tap do |gcloud_file|
15
16
  gcloud_file.store(file)
16
17
  end
17
18
  end
18
19
 
19
20
  def retrieve!(identifier)
20
- CarrierWave::Storage::GcloudFile.new(uploader, connection, uploader.store_path(identifier)).retrieve
21
+ GcloudFile.new(uploader, connection, uploader.store_path(identifier))
22
+ end
23
+
24
+ def cache!(file)
25
+ GcloudFile.new(uploader, connection, uploader.cache_path).tap do |gcloud_file|
26
+ gcloud_file.store(file)
27
+ end
28
+ end
29
+
30
+ def retrieve_from_cache!(identifier)
31
+ GcloudFile.new(uploader, connection, uploader.cache_path(identifier))
32
+ end
33
+
34
+ def clean_cache!(_seconds)
35
+ raise 'use Object Lifecycle Management to clean the cache'
21
36
  end
22
37
 
23
38
  def connection
24
39
  @connection ||= begin
25
- cert_path = Gem.loaded_specs['google-api-client'].full_gem_path+'/lib/cacerts.pem'
40
+ conn_cache = self.class.connection_cache
26
41
  ENV['SSL_CERT_FILE'] = cert_path
27
- self.class.connection_cache[credentials] ||= ::Google::Cloud.new(credentials[:gcloud_project] || ENV["GCLOUD_PROJECT"], credentials[:gcloud_keyfile] || ENV["GCLOUD_KEYFILE"]).storage
42
+ conn_cache[credentials] ||= ::Google::Cloud.new(
43
+ credentials[:gcloud_project] || ENV['GCLOUD_PROJECT'],
44
+ credentials[:gcloud_keyfile] || ENV['GCLOUD_KEYFILE']
45
+ ).storage.bucket(uploader.gcloud_bucket)
28
46
  end
29
47
  end
30
48
 
31
49
  def credentials
32
- uploader.gcloud_credentials
50
+ uploader.gcloud_credentials || {}
51
+ end
52
+
53
+ private
54
+
55
+ def cert_path
56
+ @cert_path ||= begin
57
+ gem_path = Gem.loaded_specs['google-api-client'].full_gem_path
58
+ gem_path + '/lib/cacerts.pem'
59
+ end
33
60
  end
34
61
  end
35
62
  end
36
- end
63
+ end
@@ -1,39 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CarrierWave
2
4
  module Storage
3
5
  class GcloudFile
4
-
6
+ GCLOUD_STORAGE_URL = 'https://storage.googleapis.com'
7
+
5
8
  attr_writer :file
6
- attr_accessor :uploader, :connection, :path,
7
- :gcloud_options, :file_exists
9
+ attr_accessor :uploader, :connection, :path, :gcloud_options, :file_exists
8
10
 
9
11
  delegate :content_type, :size, to: :file
10
12
 
11
13
  def initialize(uploader, connection, path)
12
- @uploader, @connection, @path = uploader, connection, path
14
+ @uploader = uploader
15
+ @connection = connection
16
+ @path = path
13
17
  end
14
18
 
15
19
  def file
16
- by_verifying_existence { @file ||= bucket.file(path) }
17
- @file
18
- end
19
- alias_method :to_file, :file
20
-
21
- def retrieve
22
- by_verifying_existence { @file ||= bucket.file(path) }
23
- self
24
- end
25
-
26
- def by_verifying_existence(&block)
27
- begin
28
- self.file_exists = true
29
- yield
30
- rescue Exception => exception
31
- self.file_exists = false if (exception.class == ::Google::Cloud::Error::NotFoundError) && (exception.message == "Not Found")
32
- end
20
+ @file ||= bucket.file(path)
33
21
  end
22
+ alias to_file file
34
23
 
35
24
  def attributes
36
- return unless file_exists
25
+ return unless exists?
37
26
  {
38
27
  content_type: file.content_type,
39
28
  size: file.size,
@@ -41,15 +30,15 @@ module CarrierWave
41
30
  etag: file.etag
42
31
  }
43
32
  end
44
-
33
+
45
34
  def delete
46
35
  deleted = file.delete
47
- self.file_exists = false if deleted
36
+ @file = nil if deleted
48
37
  deleted
49
38
  end
50
-
39
+
51
40
  def exists?
52
- self.file_exists
41
+ !file.nil?
53
42
  end
54
43
 
55
44
  def extension
@@ -62,14 +51,17 @@ module CarrierWave
62
51
  end
63
52
 
64
53
  def read
65
- tmp_file = Tempfile.new(CarrierWave::Support::UriFilename.filename(file.name))
54
+ tmp_file = Tempfile.new(
55
+ CarrierWave::Support::UriFilename.filename(file.name)
56
+ )
66
57
  (file.download tmp_file.path, verify: :all).read
67
58
  end
68
59
 
69
60
  def store(new_file)
70
- new_file_path = uploader.filename ? uploader.filename : new_file.filename
71
- # bucket.create_file new_file.path, "#{uploader.store_dir}/#{new_file_path}"
72
- bucket.create_file new_file.path, path, content_type: new_file.content_type
61
+ new_file_path = uploader.filename ? uploader.filename : new_file.filename
62
+ bucket.create_file(
63
+ new_file.path, path, content_type: new_file.content_type
64
+ )
73
65
  self
74
66
  end
75
67
 
@@ -78,28 +70,26 @@ module CarrierWave
78
70
  end
79
71
 
80
72
  def url(options = {})
81
- return unless file_exists
82
73
  uploader.gcloud_bucket_is_public ? public_url : authenticated_url
83
74
  end
84
-
75
+
85
76
  def authenticated_url(options = {})
86
- file.signed_url
77
+ bucket.signed_url(path, options)
87
78
  end
88
79
 
89
80
  def public_url
90
81
  if uploader.asset_host
91
82
  "#{uploader.asset_host}/#{path}"
92
83
  else
93
- file.public_url.to_s
84
+ "#{GCLOUD_STORAGE_URL}/#{uploader.gcloud_bucket}/#{@path}"
94
85
  end
95
86
  end
96
87
 
97
88
  private
98
89
 
99
90
  def bucket
100
- bucket ||= connection.bucket(uploader.gcloud_bucket)
91
+ connection
101
92
  end
102
-
103
93
  end
104
94
  end
105
- end
95
+ end
@@ -0,0 +1,23 @@
1
+ require 'uri'
2
+
3
+ module CarrierWave
4
+ module Utilities
5
+ module Uri
6
+ # based on Ruby < 2.0's URI.encode
7
+ SAFE_STRING = URI::REGEXP::PATTERN::UNRESERVED + '\/'
8
+ UNSAFE = Regexp.new("[^#{SAFE_STRING}]", false)
9
+
10
+ private
11
+ def encode_path(path)
12
+ path.to_s.gsub(UNSAFE) do
13
+ us = $&
14
+ tmp = ''
15
+ us.each_byte do |uc|
16
+ tmp << sprintf('%%%02X', uc)
17
+ end
18
+ tmp
19
+ end
20
+ end
21
+ end # Uri
22
+ end # Utilities
23
+ end # CarrierWave
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-google-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasdeep Singh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: google-cloud-storage
14
+ name: carrierwave
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.21.0
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.21.0
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: carrierwave
28
+ name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.11.2
33
+ version: 1.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.11.2
40
+ version: 1.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,47 +67,47 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.12'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 0.10.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 0.10.3
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: '10.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: '10.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.10.3
103
+ version: '3.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.10.3
110
+ version: '3.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: uri-query_params
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +149,7 @@ files:
149
149
  - lib/carrierwave/storage/gcloud_file.rb
150
150
  - lib/carrierwave/storage/gcloud_options.rb
151
151
  - lib/carrierwave/support/uri_filename.rb
152
+ - lib/carrierwave/utilities/uri.rb
152
153
  homepage: https://github.com/metaware/carrierwave-google-storage
153
154
  licenses:
154
155
  - MIT
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.4.8
173
+ rubygems_version: 2.6.14
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: Use gcloud for Google Cloud Storage support in CarrierWave.