shrine-configurable_storage 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8adb2989838d5f64e97338a64bbd875136979026
4
- data.tar.gz: b948c95f4bae337349d96a5f7e00354fa008cca9
3
+ metadata.gz: 970f73f0af13a1e9c1b5d1d150c59b6309ea4837
4
+ data.tar.gz: 83f00744efcbbfc8bcbd19df8f6065948457a36e
5
5
  SHA512:
6
- metadata.gz: 6205bd76319c03a35f3a3c1f3ca5df3fa4baafe4f36500ee92cfef74c01787422b66d025a119a39c86d831af75672d24d6188e31887256df555434fb76fbdc5f
7
- data.tar.gz: c65d0df33dad6a51be7ee2c08f62f54a135644f7d5e7808968e185d7a67d54a9cbafa5aedc99cf3f47944c65348d7151772be4c62731664efc85d0c1298408d5
6
+ metadata.gz: 1e405ca89737eeafcd7567f28088513f482689d74919383261f04acac07922b911cfa1f18cf574c2bb1cc1bb3e7c40005e5ffd3784e1a099446b9468bacd8a88
7
+ data.tar.gz: 39cfa6cab324b97f020ea30dc3c73907ff26be302ef6b1cd74cdfa7a625d8e3bfe60681baae50feed61e94b849aa60f55f9229294556181d79fc1c08cd03e465
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2
4
+ Fix error message (missing storage name).
5
+
3
6
  ## 0.1.1
4
7
  Use shrine base error `Shrine::Error`.
5
8
 
6
9
  ## 0.1.0
7
- Initial release
10
+ Initial release.
data/README.md CHANGED
@@ -1,71 +1,71 @@
1
- # shrine-configurable_storage
2
- [![Build Status](https://travis-ci.com/SleeplessByte/shrine-configurable_storage.svg?branch=master)](https://travis-ci.com/SleeplessByte/shrine-configurable_storage)
3
- [![Gem Version](https://badge.fury.io/rb/shrine-configurable_storage.svg)](https://badge.fury.io/rb/tempfile-fixture)
4
- [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
5
-
6
- Register Shrine storages using a key and lazy configure that storage later.
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'shrine-configurable_storage'
14
- ```
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install shrine-configurable_storage
23
-
24
- ## Usage
25
-
26
- Setup your configurable, lazy, dynamic storage by adding the plugin and calling configure.
27
-
28
- ```Ruby
29
- require 'shrine/plugins/configurable_storage'
30
-
31
- class MyUploader < Shrine
32
- plugin :configurable_storage
33
- configurable_storage_name :foo
34
- end
35
-
36
- # Somewhere else
37
- Shrine::Plugins::ConfigurableStorage.configure |config| do
38
- config[:foo] = {
39
- cache: Shrine::Storage::FileSystem.new(...),
40
- store: Shrine::Storage::S3.new(...)
41
- }
42
- end
43
- ```
44
-
45
- You can use the `:default` key (`config[:default] =`) to add fallback storage(s). You can add as many storages as you
46
- want, and just like before, you're not limited to cache and store. When finding a storage, the name will be used to find
47
- the set of storages and fallback to `:default`.
48
-
49
- ## Development
50
-
51
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
52
- also run `bin/console` for an interactive prompt that will allow you to experiment.
53
-
54
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
55
- version number in `shrine-configurable_storage.gemspec.rb`, and then run `bundle exec rake release`, which will create
56
- a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
-
58
- ## Contributing
59
-
60
- Bug reports and pull requests are welcome on GitHub at https://github.com/SleeplessByte/shrine-configurable_storage.
61
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
62
- the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
-
64
- ## License
65
-
66
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
67
-
68
- ## Code of Conduct
69
-
70
- Everyone interacting in the Shrine::ConfigurableStorage project’s codebases, issue trackers, chat rooms and mailing
71
- lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shrine-configurable_storage/blob/master/CODE_OF_CONDUCT.md).
1
+ # shrine-configurable_storage
2
+ [![Build Status](https://travis-ci.com/SleeplessByte/shrine-configurable_storage.svg?branch=master)](https://travis-ci.com/SleeplessByte/shrine-configurable_storage)
3
+ [![Gem Version](https://badge.fury.io/rb/shrine-configurable_storage.svg)](https://badge.fury.io/rb/shrine-configurable_storage)
4
+ [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
5
+
6
+ Register Shrine storages using a key and lazy configure that storage later.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'shrine-configurable_storage'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install shrine-configurable_storage
23
+
24
+ ## Usage
25
+
26
+ Setup your configurable, lazy, dynamic storage by adding the plugin and calling configure.
27
+
28
+ ```Ruby
29
+ require 'shrine/plugins/configurable_storage'
30
+
31
+ class MyUploader < Shrine
32
+ plugin :configurable_storage
33
+ configurable_storage_name :foo
34
+ end
35
+
36
+ # Somewhere else
37
+ Shrine::Plugins::ConfigurableStorage.configure do |config|
38
+ config[:foo] = {
39
+ cache: Shrine::Storage::FileSystem.new(...),
40
+ store: Shrine::Storage::S3.new(...)
41
+ }
42
+ end
43
+ ```
44
+
45
+ You can use the `:default` key (`config[:default] =`) to add fallback storage(s). You can add as many storages as you
46
+ want, and just like before, you're not limited to cache and store. When finding a storage, the name will be used to find
47
+ the set of storages and fallback to `:default`.
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
52
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
55
+ version number in `shrine-configurable_storage.gemspec.rb`, and then run `bundle exec rake release`, which will create
56
+ a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SleeplessByte/shrine-configurable_storage.
61
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
62
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
67
+
68
+ ## Code of Conduct
69
+
70
+ Everyone interacting in the Shrine::ConfigurableStorage project’s codebases, issue trackers, chat rooms and mailing
71
+ lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shrine-configurable_storage/blob/master/CODE_OF_CONDUCT.md).
@@ -1,96 +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 < ::Shrine::Error
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 = {}
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 < ::Shrine::Error
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_name
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 = {}
@@ -1,47 +1,47 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'shrine-configurable_storage'
8
- spec.version = '0.1.1'
9
- spec.authors = ['Derk-Jan Karrenbeld']
10
- spec.email = ['derk-jan+github@karrenbeld.info']
11
-
12
- spec.summary = 'Register Shrine storages using a key and lazy configure that storage later.'
13
- spec.license = 'MIT'
14
-
15
- spec.metadata = {
16
- 'bug_tracker_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/issues',
17
- 'changelog_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/CHANGELOG.md',
18
- 'homepage_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage',
19
- 'source_code_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage'
20
- }
21
-
22
-
23
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
- # to allow pushing to a single host or delete this section to allow pushing to any host.
25
- if spec.respond_to?(:metadata)
26
- # spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
27
- else
28
- raise 'RubyGems 2.0 or newer is required to protect against ' \
29
- 'public gem pushes.'
30
- end
31
-
32
- # Specify which files should be added to the gem when it is released.
33
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
- f.match(%r{^(test|spec|features)/})
36
- end
37
- spec.bindir = 'exe'
38
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
- spec.require_paths = ['lib']
40
-
41
- spec.add_dependency 'shrine', '>= 2.0.0', '< 3.0.0'
42
-
43
- spec.add_development_dependency 'bundler', '~> 1.16'
44
- spec.add_development_dependency 'minitest', '~> 5.0'
45
- spec.add_development_dependency 'rake', '~> 10.0'
46
- spec.add_development_dependency 'shrine-memory'
47
- end
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'shrine-configurable_storage'
8
+ spec.version = '0.1.2'
9
+ spec.authors = ['Derk-Jan Karrenbeld']
10
+ spec.email = ['derk-jan+github@karrenbeld.info']
11
+
12
+ spec.summary = 'Register Shrine storages using a key and lazy configure that storage later.'
13
+ spec.license = 'MIT'
14
+
15
+ spec.metadata = {
16
+ 'bug_tracker_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/issues',
17
+ 'changelog_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage/CHANGELOG.md',
18
+ 'homepage_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage',
19
+ 'source_code_uri' => 'https://github.com/SleeplessByte/shrine-configurable_storage'
20
+ }
21
+
22
+
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
25
+ if spec.respond_to?(:metadata)
26
+ # spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
27
+ else
28
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
29
+ 'public gem pushes.'
30
+ end
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
+ f.match(%r{^(test|spec|features)/})
36
+ end
37
+ spec.bindir = 'exe'
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.add_dependency 'shrine', '>= 2.0.0', '< 3.0.0'
42
+
43
+ spec.add_development_dependency 'bundler', '~> 1.16'
44
+ spec.add_development_dependency 'minitest', '~> 5.0'
45
+ spec.add_development_dependency 'rake', '~> 10.0'
46
+ spec.add_development_dependency 'shrine-memory'
47
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-configurable_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-09 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine