paperclip-eitheror 0.1.0 → 0.1.1

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: 977bcd0b0e3c7535687ef21d01803b7c616659c6
4
- data.tar.gz: fe78f2825400ace39fc663f90d90d4fce0b1388e
3
+ metadata.gz: 0eaac3a917d3a5ec24a54f230ea46087167b9dde
4
+ data.tar.gz: 936ba75f84bcb492118e25230f8374bfe5fb2f5a
5
5
  SHA512:
6
- metadata.gz: bbc423e8ba839df5f6cae5d71c84342b568bd19a67383c79e07ba9bfed32975ea41fe756710adb04480811f5f14debddf810c5568339f164926905d5a2ce18e1
7
- data.tar.gz: 8765c21b4b21be2f15d6d7fbf2d3d13551ba873cf59ccf8433db2df9a27523085e557da80f168093c23a6c035f484d6a00bd5d3d44086956528c12c007635daa
6
+ metadata.gz: 98b2c8152ec72ce8e98dd0d9ae828b6445c764715348de5c6308331498d18895f413d43ceb18112dc516c08becc0ab95f7df2f6d8ee2291f4a37b4346d30d7eb
7
+ data.tar.gz: c4ae600bb32c35013922744768feff5ef47994be28479f633df03dccf9932b96b6df3c27abc79187354b5ff98b0aeb732a45fea81f3da1f32c2eb683d9dd66da
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Paperclip::Eitheror
2
+
2
3
  [![Build Status](https://travis-ci.org/powerhome/paperclip-eitheror.svg?branch=master)](https://travis-ci.org/powerhome/paperclip-eitheror)
3
4
 
4
5
  A [Paperclip](https://github.com/thoughtbot/paperclip/) Storage which supports a secondary (called 'or') storage as a fallback while using the primary one (called 'either').
@@ -123,7 +124,7 @@ class User < ActiveRecord::Base
123
124
  end
124
125
  ```
125
126
 
126
- # `:autosync`
127
+ ## The `:autosync` Option
127
128
 
128
129
  You can configure `paperclip-eitheror` to automatically synchronize attachments from the **or** (fallback) storage to **either** (primary).
129
130
 
@@ -137,7 +138,30 @@ has_attached_file :avatar, {
137
138
  }
138
139
  ```
139
140
 
140
- # Method aliasing/overriding
141
+ ## Disabling "Either": The `enabled: false` Option
142
+
143
+ In case you need to set up `paperclip-eitheror` on your app, but are not yet ready to enable the primary storage, you may disable it by using `enabled: false` in the **either** options list, as follows:
144
+
145
+ ```ruby
146
+ has_attached_file :avatar, {
147
+ storage: :eitheror,
148
+ either: {
149
+ storage: :fog,
150
+ enabled: false,
151
+ path: ':attachment/:id/:style/:filename',
152
+ url: ':attachment/:id/:style/:filename'
153
+ },
154
+ or: {
155
+ storage: :filesystem,
156
+ url: '/api/v1/attachments/:attachment/:id/:style',
157
+ path: ':rails_root/public/attachments/:class/:attachment/:style/:filename',
158
+ }
159
+ }
160
+ ```
161
+
162
+ That comes specially handy if you need to enable/disable the primary storage based off a config flag, allowing, for instance, the primary storage to be disabled on a per-environment basis.
163
+
164
+ ## Method Aliasing/Overriding
141
165
 
142
166
  Different storages provide different ways of accessing attachments.
143
167
  For instance, when using `:fog` storage, you have access to methods which only make sense to that particular storage.
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Eitheror
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ module Paperclip
3
3
  module Eitheror
4
4
  def self.extended base
5
5
  base.instance_eval do
6
+ base.options[:either][:enabled] = true if base.options[:either][:enabled].nil?
6
7
  @either = Attachment.new(base.name, base.instance, base.options.merge(base.options[:either]))
7
8
  @or = Attachment.new(base.name, base.instance, base.options.merge(base.options[:or]))
8
9
 
@@ -70,6 +71,7 @@ module Paperclip
70
71
  end
71
72
 
72
73
  def usable_storage
74
+ return @or unless @either.options[:enabled]
73
75
  return @either if !@or.exists? || @either.exists?
74
76
  options[:autosync] && sync ? @either : @or
75
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-eitheror
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Abegg
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.4.5.1
150
+ rubygems_version: 2.4.8
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Storage for Paperclip which will fallback in case of a file not existing