shrine-configurable_storage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bc5f08e6228fd04a56aa43bfa204018c0c9bdcc
4
+ data.tar.gz: 977a5695ab0679ced3086cc4322f925e0cc17207
5
+ SHA512:
6
+ metadata.gz: b3bf5c0f9b6d946ac336fb6e18ba2b41a559bec77e527a1eda4f1ac430bff105cc75e91f623c987ad07c4924afbe0f9c0da6e2f04625baa3f4ebfba810b07a70
7
+ data.tar.gz: 5b5d4519e1975683db7713fb82254c36edcc86b42b1cb1f56f5991c90d49b92ba44e25ad952d6436f2cf30e66497000153fcfb6aeacf7c689b6829bd6685408c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .idea/
11
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - 'lib/**/*.rb'
5
+ Exclude:
6
+ - 'Gemfile'
7
+ - 'bin/**/*'
8
+ TargetRubyVersion: 2.3
9
+
10
+ Style/EndOfLine:
11
+ EnforcedStyle: lf
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - rbx-3
10
+ - ruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+ - rvm: rbx-3
15
+ - rvm: 2.6
16
+ before_install:
17
+ - gem update --system
18
+ - gem --version
19
+ install:
20
+ - bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+ Initial release
@@ -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 derk-jan+github@karrenbeld.info. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in shrine-configurable_storage.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Derk-Jan Karrenbeld
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,68 @@
1
+ # shrine-configurable_storage
2
+
3
+ Register Shrine storages using a key and lazy configure that storage later.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shrine-configurable_storage'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shrine-configurable_storage
20
+
21
+ ## Usage
22
+
23
+ Setup your configurable, lazy, dynamic storage by adding the plugin and calling configure.
24
+
25
+ ```Ruby
26
+ require 'shrine/plugins/configurable_storage'
27
+
28
+ class MyUploader < Shrine
29
+ plugin :configurable_storage
30
+ configurable_storage_name :foo
31
+ end
32
+
33
+ # Somewhere else
34
+ Shrine::Plugins::ConfigurableStorage.configure |config| do
35
+ config[:foo] = {
36
+ cache: Shrine::Storage::FileSystem.new(...),
37
+ store: Shrine::Storage::S3.new(...)
38
+ }
39
+ end
40
+ ```
41
+
42
+ You can use the `:default` key (`config[:default] =`) to add fallback storage(s). You can add as many storages as you
43
+ want, and just like before, you're not limited to cache and store. When finding a storage, the name will be used to find
44
+ the set of storages and fallback to `:default`.
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
49
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
52
+ version number in `shrine-configurable_storage.gemspec.rb`, and then run `bundle exec rake release`, which will create
53
+ a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SleeplessByte/shrine-configurable_storage.
58
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
59
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
64
+
65
+ ## Code of Conduct
66
+
67
+ Everyone interacting in the Shrine::ConfigurableStorage project’s codebases, issue trackers, chat rooms and mailing
68
+ lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shrine-configurable_storage/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shrine/configurable_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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shrine'
4
+
5
+ class Shrine
6
+ module Plugins
7
+ # The {ConfigurableStorage} plugin allows you to register a storage using a
8
+ # config key, and evaluate the storage class dynamically depending on the
9
+ # key. The configuration is global and can be shared across uploaders.
10
+ #
11
+ # Example: Setup storage for images
12
+ #
13
+ # # in your uploader
14
+ #
15
+ # plugin :configurable_storage
16
+ # configurable_storage_name :images
17
+ #
18
+ # # in an initializer, or somewhere else (because this is lazy)
19
+ #
20
+ # Shrine::Plugins::ConfigurableStorage.configure do |config|
21
+ # config[:images] = {
22
+ # cache: Shrine::Storage::Memory.new,
23
+ # store: Shrine::Storage::FileSystem.new('uploads', prefix: 'img')
24
+ # }
25
+ # end
26
+ #
27
+ module ConfigurableStorage
28
+
29
+ class << self
30
+ def fetch(arg, &block)
31
+ configuration.fetch(arg, &block)
32
+ end
33
+
34
+ def configure(uploader = nil, *_args)
35
+ return uploader.setup unless block_given?
36
+
37
+ yield configuration
38
+ end
39
+
40
+ attr_accessor :configuration
41
+ end
42
+
43
+ class StorageNotConfigured < RuntimeError
44
+ end
45
+
46
+ module ClassMethods
47
+ def setup
48
+ @storage_name = nil
49
+ @memoized_storage = {}
50
+ end
51
+
52
+ def configurable_storage_name(name)
53
+ name = name.to_sym
54
+ @storage_name = name
55
+ @memoized_storage.delete(name)
56
+ end
57
+
58
+ def find_storage(name)
59
+ return super unless @storage_name
60
+
61
+ name = name.to_sym
62
+ @memoized_storage.fetch(name) do
63
+ group = ConfigurableStorage.fetch(@storage_name || :default) do
64
+ ConfigurableStorage.fetch(:default) do
65
+ raise_storage_not_configured(name)
66
+ end
67
+ end
68
+ group[name] || super
69
+ end
70
+ end
71
+
72
+ def raise_storage_not_configured(name)
73
+ raise(
74
+ StorageNotConfigured,
75
+ format(
76
+ "Uploader storage not set up for '%<storage_name>s'. " \
77
+ "Make sure you setup the configurable storage: \n\n" \
78
+ "Shrine::Plugins::ConfigurableStorage.configure do |config| \n" \
79
+ " config[:%<storage_key>s] = { \n"\
80
+ " cache: Shrine::Storage::..., \n"\
81
+ " store: Shrine::Storage::... \n"\
82
+ " }.freeze \n" \
83
+ 'end',
84
+ storage_name: name,
85
+ storage_key: @storage_key
86
+ )
87
+ )
88
+ end
89
+ end
90
+ end
91
+
92
+ register_plugin(:configurable_storage, ConfigurableStorage)
93
+ end
94
+ end
95
+
96
+ Shrine::Plugins::ConfigurableStorage.configuration = {}
@@ -0,0 +1,48 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'shrine-configurable_storage'
9
+ spec.version = '0.1.0'
10
+ spec.authors = ['Derk-Jan Karrenbeld']
11
+ spec.email = ['derk-jan+github@karrenbeld.info']
12
+
13
+ spec.summary = 'Register Shrine storages using a key and lazy configure that storage later.'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata = {
17
+ 'bug_tracker_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/issues',
18
+ 'changelog_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/CHANGELOG.md',
19
+ 'homepage_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage',
20
+ 'source_code_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage'
21
+ }
22
+
23
+
24
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
25
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
26
+ if spec.respond_to?(:metadata)
27
+ # spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
28
+ else
29
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
30
+ 'public gem pushes.'
31
+ end
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
36
+ f.match(%r{^(test|spec|features)/})
37
+ end
38
+ spec.bindir = 'exe'
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ['lib']
41
+
42
+ spec.add_dependency 'shrine', '>= 2.0.0', '< 3.0.0'
43
+
44
+ spec.add_development_dependency 'bundler', '~> 1.16'
45
+ spec.add_development_dependency 'minitest', '~> 5.0'
46
+ spec.add_development_dependency 'rake', '~> 10.0'
47
+ spec.add_development_dependency 'shrine-memory'
48
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shrine-configurable_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Derk-Jan Karrenbeld
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shrine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: shrine-memory
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description:
90
+ email:
91
+ - derk-jan+github@karrenbeld.info
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rubocop.yml"
98
+ - ".travis.yml"
99
+ - CHANGELOG.md
100
+ - CODE_OF_CONDUCT.md
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - bin/console
106
+ - bin/setup
107
+ - lib/shrine/plugins/configurable_storage.rb
108
+ - shrine-configurable_storage.gemspec
109
+ homepage:
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ bug_tracker_uri: https://github.com/SleeplessByte/shrine-configurable_storage/issues
114
+ changelog_uri: https://github.com/SleeplessByte/shrine-configurable_storage/CHANGELOG.md
115
+ homepage_uri: https://github.com/SleeplessByte/shrine-configurable_storage
116
+ source_code_uri: https://github.com/SleeplessByte/shrine-configurable_storage
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.6.14.1
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Register Shrine storages using a key and lazy configure that storage later.
137
+ test_files: []