clowne_active_storage 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 +11 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +148 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/clowne_active_storage.gemspec +30 -0
- data/lib/clowne_active_storage.rb +20 -0
- data/lib/clowne_active_storage/declarations/include_attached.rb +19 -0
- data/lib/clowne_active_storage/helpers/active_storage_downloader.rb +46 -0
- data/lib/clowne_active_storage/resolvers/attachment_association.rb +55 -0
- data/lib/clowne_active_storage/version.rb +3 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a92d3bbbbb57b19da167dfc09a90dd0e39789f22899042234a4a61f4230ab12
|
4
|
+
data.tar.gz: ca1b85cd08e439de960f9268bb981505a8b58b91cbaf1219573a6298283da77b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8ca19bd7e5730a4f1c60e09a231ed76b9c6ca1a4e809982ee9eea54f761eb88539f095df8699c9e04bb3195f7a037810e8f521c526b27ac7bed95301a8b6ed6
|
7
|
+
data.tar.gz: 66be73c7f70706f66e7a89aef7a66065ebcc53a655d9becb853fbccfed501a3fe873d8f955622360cd049b53e38cebd7ee45aa85f80e4962f42e2013ba703466
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## 0.1.0 — 2018-08-02
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Adds the command `include_attached` to Clowne’s cloner DSL.
|
14
|
+
|
15
|
+
[unreleased]: https://github.com/cbothner/clowne_active_storage/compare/v0.1.0...HEAD
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at cameronbothner@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
clowne_active_storage (0.1.0)
|
5
|
+
clowne
|
6
|
+
rails
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (5.2.0)
|
12
|
+
actionpack (= 5.2.0)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailer (5.2.0)
|
16
|
+
actionpack (= 5.2.0)
|
17
|
+
actionview (= 5.2.0)
|
18
|
+
activejob (= 5.2.0)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.2.0)
|
22
|
+
actionview (= 5.2.0)
|
23
|
+
activesupport (= 5.2.0)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.2.0)
|
29
|
+
activesupport (= 5.2.0)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.2.0)
|
35
|
+
activesupport (= 5.2.0)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.2.0)
|
38
|
+
activesupport (= 5.2.0)
|
39
|
+
activerecord (5.2.0)
|
40
|
+
activemodel (= 5.2.0)
|
41
|
+
activesupport (= 5.2.0)
|
42
|
+
arel (>= 9.0)
|
43
|
+
activestorage (5.2.0)
|
44
|
+
actionpack (= 5.2.0)
|
45
|
+
activerecord (= 5.2.0)
|
46
|
+
marcel (~> 0.3.1)
|
47
|
+
activesupport (5.2.0)
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
|
+
i18n (>= 0.7, < 2)
|
50
|
+
minitest (~> 5.1)
|
51
|
+
tzinfo (~> 1.1)
|
52
|
+
arel (9.0.0)
|
53
|
+
builder (3.2.3)
|
54
|
+
byebug (10.0.2)
|
55
|
+
clowne (0.2.0)
|
56
|
+
concurrent-ruby (1.0.5)
|
57
|
+
crass (1.0.4)
|
58
|
+
diff-lcs (1.3)
|
59
|
+
erubi (1.7.1)
|
60
|
+
globalid (0.4.1)
|
61
|
+
activesupport (>= 4.2.0)
|
62
|
+
i18n (1.0.1)
|
63
|
+
concurrent-ruby (~> 1.0)
|
64
|
+
loofah (2.2.2)
|
65
|
+
crass (~> 1.0.2)
|
66
|
+
nokogiri (>= 1.5.9)
|
67
|
+
mail (2.7.0)
|
68
|
+
mini_mime (>= 0.1.1)
|
69
|
+
marcel (0.3.2)
|
70
|
+
mimemagic (~> 0.3.2)
|
71
|
+
method_source (0.9.0)
|
72
|
+
mimemagic (0.3.2)
|
73
|
+
mini_mime (1.0.0)
|
74
|
+
mini_portile2 (2.3.0)
|
75
|
+
minitest (5.11.3)
|
76
|
+
nio4r (2.3.1)
|
77
|
+
nokogiri (1.8.4)
|
78
|
+
mini_portile2 (~> 2.3.0)
|
79
|
+
rack (2.0.5)
|
80
|
+
rack-test (1.1.0)
|
81
|
+
rack (>= 1.0, < 3)
|
82
|
+
rails (5.2.0)
|
83
|
+
actioncable (= 5.2.0)
|
84
|
+
actionmailer (= 5.2.0)
|
85
|
+
actionpack (= 5.2.0)
|
86
|
+
actionview (= 5.2.0)
|
87
|
+
activejob (= 5.2.0)
|
88
|
+
activemodel (= 5.2.0)
|
89
|
+
activerecord (= 5.2.0)
|
90
|
+
activestorage (= 5.2.0)
|
91
|
+
activesupport (= 5.2.0)
|
92
|
+
bundler (>= 1.3.0)
|
93
|
+
railties (= 5.2.0)
|
94
|
+
sprockets-rails (>= 2.0.0)
|
95
|
+
rails-dom-testing (2.0.3)
|
96
|
+
activesupport (>= 4.2.0)
|
97
|
+
nokogiri (>= 1.6)
|
98
|
+
rails-html-sanitizer (1.0.4)
|
99
|
+
loofah (~> 2.2, >= 2.2.2)
|
100
|
+
railties (5.2.0)
|
101
|
+
actionpack (= 5.2.0)
|
102
|
+
activesupport (= 5.2.0)
|
103
|
+
method_source
|
104
|
+
rake (>= 0.8.7)
|
105
|
+
thor (>= 0.18.1, < 2.0)
|
106
|
+
rake (10.5.0)
|
107
|
+
rspec (3.7.0)
|
108
|
+
rspec-core (~> 3.7.0)
|
109
|
+
rspec-expectations (~> 3.7.0)
|
110
|
+
rspec-mocks (~> 3.7.0)
|
111
|
+
rspec-core (3.7.1)
|
112
|
+
rspec-support (~> 3.7.0)
|
113
|
+
rspec-expectations (3.7.0)
|
114
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
115
|
+
rspec-support (~> 3.7.0)
|
116
|
+
rspec-mocks (3.7.0)
|
117
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
118
|
+
rspec-support (~> 3.7.0)
|
119
|
+
rspec-support (3.7.1)
|
120
|
+
sprockets (3.7.2)
|
121
|
+
concurrent-ruby (~> 1.0)
|
122
|
+
rack (> 1, < 3)
|
123
|
+
sprockets-rails (3.2.1)
|
124
|
+
actionpack (>= 4.0)
|
125
|
+
activesupport (>= 4.0)
|
126
|
+
sprockets (>= 3.0.0)
|
127
|
+
sqlite3 (1.3.13)
|
128
|
+
thor (0.20.0)
|
129
|
+
thread_safe (0.3.6)
|
130
|
+
tzinfo (1.2.5)
|
131
|
+
thread_safe (~> 0.1)
|
132
|
+
websocket-driver (0.7.0)
|
133
|
+
websocket-extensions (>= 0.1.0)
|
134
|
+
websocket-extensions (0.1.3)
|
135
|
+
|
136
|
+
PLATFORMS
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
bundler (~> 1.16)
|
141
|
+
byebug
|
142
|
+
clowne_active_storage!
|
143
|
+
rake (~> 10.0)
|
144
|
+
rspec (~> 3.0)
|
145
|
+
sqlite3
|
146
|
+
|
147
|
+
BUNDLED WITH
|
148
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Cameron Bothner
|
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,49 @@
|
|
1
|
+
# clowne_active_storage
|
2
|
+
|
3
|
+
[![Gem](https://img.shields.io/gem/v/clowne_active_storage.svg)](https://rubygems.org/gems/clowne_active_storage)
|
4
|
+
|
5
|
+
[Clowne][] is a flexible gem for making deep clones of your models. It supports ActiveRecord associations out of the box, so the whole dependency graph can be copied. This gem adds support for ActiveStorage attachments so they can be cloned in the process.
|
6
|
+
|
7
|
+
[clowne]: https://github.com/palkan/clowne
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'clowne_active_storage'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This gem adds one command to Clowne’s DSL: `include_attached`. You can use it like this:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class PostCloner < Clowne::Cloner
|
27
|
+
include_attached :cover_image, :files
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
`include_attached` can handle `has_one_attached` and `has_many_attached` ActiveStorage associations in the same command.
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cbothner/clowne_active_storage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
46
|
+
|
47
|
+
## Code of Conduct
|
48
|
+
|
49
|
+
Everyone interacting in the ClowneActiveStorage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cbothner/clowne_active_storage/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "clowne_active_storage"
|
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,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'clowne_active_storage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'clowne_active_storage'
|
8
|
+
s.version = ClowneActiveStorage::VERSION
|
9
|
+
s.authors = ['Cameron Bothner']
|
10
|
+
s.email = ['cameronbothner@gmail.com']
|
11
|
+
|
12
|
+
s.summary = 'Clone ActiveStorage attachment associations with Clowne'
|
13
|
+
s.homepage = 'https://github.com/cbothner/clowne_active_storage'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
s.bindir = 'exe'
|
20
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.add_dependency 'clowne'
|
24
|
+
s.add_dependency 'rails'
|
25
|
+
|
26
|
+
s.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
s.add_development_dependency 'byebug'
|
28
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'clowne'
|
2
|
+
require 'active_record'
|
3
|
+
require 'clowne/adapters/active_record'
|
4
|
+
|
5
|
+
require 'clowne_active_storage/version'
|
6
|
+
require 'clowne_active_storage/declarations/include_attached'
|
7
|
+
require 'clowne_active_storage/resolvers/attachment_association'
|
8
|
+
|
9
|
+
Clowne::Declarations.add :include_attached do |*names|
|
10
|
+
names.each do |name|
|
11
|
+
decl = ClowneActiveStorage::Declarations::IncludeAttached.new name
|
12
|
+
declarations.push decl
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Clowne::Adapters::ActiveRecord.register_resolver(
|
17
|
+
:attachment_association,
|
18
|
+
ClowneActiveStorage::Resolvers::AttachmentAssociation,
|
19
|
+
after: :nullify
|
20
|
+
)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClowneActiveStorage
|
4
|
+
module Declarations
|
5
|
+
# DSL to add associations to ActiveStorage Attachments and Blobs for single
|
6
|
+
# attachments
|
7
|
+
class IncludeAttached < ::Clowne::Declarations::Base
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(name)
|
11
|
+
@name = name.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def compile(plan)
|
15
|
+
plan.set :attachment_association, self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Imported from the future
|
4
|
+
# https://github.com/rails/rails/commit/ee21b7c2eb64def8f00887a9fafbd77b85f464f1#diff-c76fb6202b7f95a08fe12f40c4999ac9
|
5
|
+
class ActiveStorageDownloader
|
6
|
+
attr_reader :blob, :tempdir
|
7
|
+
def initialize(blob, tempdir: nil)
|
8
|
+
@blob = blob
|
9
|
+
@tempdir = tempdir
|
10
|
+
end
|
11
|
+
|
12
|
+
def download_blob_to_tempfile
|
13
|
+
open_tempfile do |file|
|
14
|
+
download_blob_to file
|
15
|
+
verify_integrity_of file
|
16
|
+
yield file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def open_tempfile
|
23
|
+
file = Tempfile.open(
|
24
|
+
["ActiveStorage-#{blob.id}-", blob.filename.extension_with_delimiter],
|
25
|
+
tempdir
|
26
|
+
)
|
27
|
+
|
28
|
+
begin
|
29
|
+
yield file
|
30
|
+
ensure
|
31
|
+
file.close!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def download_blob_to(file)
|
36
|
+
file.binmode
|
37
|
+
blob.download { |chunk| file.write(chunk) }
|
38
|
+
file.flush
|
39
|
+
file.rewind
|
40
|
+
end
|
41
|
+
|
42
|
+
def verify_integrity_of(file)
|
43
|
+
return if Digest::MD5.file(file).base64digest == blob.checksum
|
44
|
+
raise ActiveStorage::IntegrityError
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClowneActiveStorage
|
4
|
+
module Resolvers
|
5
|
+
# Clone the files attached to source and attach the clones to the record
|
6
|
+
class AttachmentAssociation
|
7
|
+
def self.call(source, record, declaration, **)
|
8
|
+
new(source, record, declaration).call
|
9
|
+
rescue Errno::ENOENT
|
10
|
+
record
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :source, :record, :declaration
|
14
|
+
|
15
|
+
def initialize(source, record, declaration)
|
16
|
+
@source = source
|
17
|
+
@record = record
|
18
|
+
@declaration = declaration
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
return record unless source_association.attached?
|
23
|
+
|
24
|
+
source_association.attachments.each do |attachment|
|
25
|
+
open_attached attachment do |tempfile|
|
26
|
+
record_association.attach(
|
27
|
+
io: tempfile, filename: attachment.filename,
|
28
|
+
content_type: attachment.content_type
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
record
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def source_association
|
38
|
+
source.send declaration.name
|
39
|
+
end
|
40
|
+
|
41
|
+
def record_association
|
42
|
+
record.send declaration.name
|
43
|
+
end
|
44
|
+
|
45
|
+
def open_attached(attached, &blk)
|
46
|
+
if attached.respond_to? :open
|
47
|
+
attached.open(&blk)
|
48
|
+
else
|
49
|
+
require 'clowne_active_storage/helpers/active_storage_downloader'
|
50
|
+
ActiveStorageDownloader.new(attached).download_blob_to_tempfile(&blk)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clowne_active_storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Bothner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clowne
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- cameronbothner@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".ruby-version"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- clowne_active_storage.gemspec
|
118
|
+
- lib/clowne_active_storage.rb
|
119
|
+
- lib/clowne_active_storage/declarations/include_attached.rb
|
120
|
+
- lib/clowne_active_storage/helpers/active_storage_downloader.rb
|
121
|
+
- lib/clowne_active_storage/resolvers/attachment_association.rb
|
122
|
+
- lib/clowne_active_storage/version.rb
|
123
|
+
homepage: https://github.com/cbothner/clowne_active_storage
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.7.3
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Clone ActiveStorage attachment associations with Clowne
|
147
|
+
test_files: []
|