activestorage-cascade 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +10 -0
- data/activestorage-cascade.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/active_storage/cascade.rb +4 -0
- data/lib/active_storage/cascade/version.rb +7 -0
- data/lib/active_storage/service/cascade_service.rb +55 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a27905dd06ad2ac414a9f30bfb3e802e2f10f4569c738ee4342a0dfe961ecc5
|
4
|
+
data.tar.gz: da342d2bb7c11a9b9051d75f92b33f053c44438b8dcc5dfc024f5b5c1842608d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 974e3ac6483c46ce58397f10c5d018d3721151936f3970c00122fb65e5d54a5909609203976a91e6533779cc5f3f4e7371468e1a81aacf1602dd938198add1dd
|
7
|
+
data.tar.gz: 9d084569494250c9334957d838d4cbddeaadefd62bd561d2faa417d4d769bb55c742098e08d8b5f56fee10a0f3082d746ed00f3978674017273ab669a7f9b700
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activestorage-cascade (0.1.0)
|
5
|
+
activestorage (> 5.2.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (6.0.2.2)
|
11
|
+
actionview (= 6.0.2.2)
|
12
|
+
activesupport (= 6.0.2.2)
|
13
|
+
rack (~> 2.0, >= 2.0.8)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.2.2)
|
18
|
+
activesupport (= 6.0.2.2)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activejob (6.0.2.2)
|
24
|
+
activesupport (= 6.0.2.2)
|
25
|
+
globalid (>= 0.3.6)
|
26
|
+
activemodel (6.0.2.2)
|
27
|
+
activesupport (= 6.0.2.2)
|
28
|
+
activerecord (6.0.2.2)
|
29
|
+
activemodel (= 6.0.2.2)
|
30
|
+
activesupport (= 6.0.2.2)
|
31
|
+
activestorage (6.0.2.2)
|
32
|
+
actionpack (= 6.0.2.2)
|
33
|
+
activejob (= 6.0.2.2)
|
34
|
+
activerecord (= 6.0.2.2)
|
35
|
+
marcel (~> 0.3.1)
|
36
|
+
activesupport (6.0.2.2)
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
38
|
+
i18n (>= 0.7, < 2)
|
39
|
+
minitest (~> 5.1)
|
40
|
+
tzinfo (~> 1.1)
|
41
|
+
zeitwerk (~> 2.2)
|
42
|
+
builder (3.2.4)
|
43
|
+
concurrent-ruby (1.1.6)
|
44
|
+
crass (1.0.6)
|
45
|
+
erubi (1.9.0)
|
46
|
+
globalid (0.4.2)
|
47
|
+
activesupport (>= 4.2.0)
|
48
|
+
i18n (1.8.2)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
loofah (2.5.0)
|
51
|
+
crass (~> 1.0.2)
|
52
|
+
nokogiri (>= 1.5.9)
|
53
|
+
marcel (0.3.3)
|
54
|
+
mimemagic (~> 0.3.2)
|
55
|
+
mimemagic (0.3.4)
|
56
|
+
mini_portile2 (2.4.0)
|
57
|
+
minitest (5.14.0)
|
58
|
+
nokogiri (1.10.9)
|
59
|
+
mini_portile2 (~> 2.4.0)
|
60
|
+
rack (2.2.2)
|
61
|
+
rack-test (1.1.0)
|
62
|
+
rack (>= 1.0, < 3)
|
63
|
+
rails-dom-testing (2.0.3)
|
64
|
+
activesupport (>= 4.2.0)
|
65
|
+
nokogiri (>= 1.6)
|
66
|
+
rails-html-sanitizer (1.3.0)
|
67
|
+
loofah (~> 2.3)
|
68
|
+
rake (12.3.3)
|
69
|
+
thread_safe (0.3.6)
|
70
|
+
tzinfo (1.2.7)
|
71
|
+
thread_safe (~> 0.1)
|
72
|
+
zeitwerk (2.3.0)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
activestorage-cascade!
|
79
|
+
minitest (~> 5.0)
|
80
|
+
rake (~> 12.0)
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Mikko Kokkonen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# activestorage-cascade
|
2
|
+
|
3
|
+
This gem adds support for cascading services for ActiveStorage.
|
4
|
+
This is ideal for development or staging environment where database refers
|
5
|
+
actual objects in the production S3 bucket, but only as read-only.
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
```
|
10
|
+
# config/storage.yml
|
11
|
+
# Services
|
12
|
+
disk:
|
13
|
+
service: Disk
|
14
|
+
root: <%= Rails.root.join("tmp/storage") %>
|
15
|
+
|
16
|
+
amazon:
|
17
|
+
service: S3
|
18
|
+
access_key_id: <%= Settings.aws.access_key_id %>
|
19
|
+
secret_access_key: <%= Settings.aws.secret_access_key %>
|
20
|
+
region: <%= Settings.aws.region %>
|
21
|
+
bucket: <%= Settings.aws.bucket %>
|
22
|
+
|
23
|
+
# Configuration
|
24
|
+
development:
|
25
|
+
service: Cascade
|
26
|
+
primary: disk
|
27
|
+
secondary: amazon
|
28
|
+
```
|
29
|
+
|
30
|
+
```
|
31
|
+
# config/environments/development.rb
|
32
|
+
Rails.application.configure do
|
33
|
+
config.active_storage.service = :development
|
34
|
+
end
|
35
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/active_storage/cascade/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'activestorage-cascade'
|
7
|
+
spec.version = ActiveStorage::Cascade::VERSION
|
8
|
+
spec.authors = ['Mikko Kokkonen']
|
9
|
+
spec.email = ['mikko@mikian.com']
|
10
|
+
|
11
|
+
spec.summary = 'Cascading Service Support for ActiveStorage'
|
12
|
+
spec.description = 'Allows to use two services, primary and secondary for ActiveStorage'
|
13
|
+
spec.homepage = 'https://github.com/mikian/activestorage-cascade'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'activestorage', '>= 5.2.2'
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "active_storage/cascade"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
5
|
+
module ActiveStorage
|
6
|
+
class Service
|
7
|
+
class CascadeService < Service
|
8
|
+
attr_reader :primary, :secondary
|
9
|
+
|
10
|
+
delegate :upload, :update_metadata, :delete, :delete_prefixed, :url_for_direct_upload, :headers_for_direct_upload,
|
11
|
+
to: :primary
|
12
|
+
|
13
|
+
def self.build(primary:, secondary:, configurator:, **_options) #:nodoc:
|
14
|
+
new(
|
15
|
+
primary: configurator.build(primary),
|
16
|
+
secondary: configurator.build(secondary)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(primary:, secondary:)
|
21
|
+
@primary = primary
|
22
|
+
@secondary = secondary
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return the content of the file at the +key+.
|
26
|
+
def download(key)
|
27
|
+
service(key).download(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the partial content in the byte +range+ of the file at the +key+.
|
31
|
+
def download_chunk(key, range)
|
32
|
+
service(key).download_chunk(key, range)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Return +true+ if a file exists at the +key+.
|
36
|
+
def exist?(key)
|
37
|
+
primary.exist?(key) || secondary.exist?(key)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a signed, temporary URL for the file at the +key+. The URL will be valid for the amount
|
41
|
+
# of seconds specified in +expires_in+. You most also provide the +disposition+ (+:inline+ or +:attachment+),
|
42
|
+
# +filename+, and +content_type+ that you wish the file to be served with on request.
|
43
|
+
def url(key, expires_in:, disposition:, filename:, content_type:)
|
44
|
+
service(key)
|
45
|
+
.url(key, expires_in: expires_in, disposition: disposition, filename: filename, content_type: content_type)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def service(key)
|
51
|
+
primary.exist?(key) ? primary : secondary
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activestorage-cascade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikko Kokkonen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activestorage
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.2
|
27
|
+
description: Allows to use two services, primary and secondary for ActiveStorage
|
28
|
+
email:
|
29
|
+
- mikko@mikian.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- activestorage-cascade.gemspec
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- lib/active_storage/cascade.rb
|
44
|
+
- lib/active_storage/cascade/version.rb
|
45
|
+
- lib/active_storage/service/cascade_service.rb
|
46
|
+
homepage: https://github.com/mikian/activestorage-cascade
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://github.com/mikian/activestorage-cascade
|
51
|
+
source_code_uri: https://github.com/mikian/activestorage-cascade
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.3.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.1.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Cascading Service Support for ActiveStorage
|
71
|
+
test_files: []
|