paperclip-defaults 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,15 +14,6 @@ To use Paperclip::Defaults simply add it to your Gemfile and update config/appli
14
14
  config.paperclip_defaults = {default_url: "http://www.example.com/missing.png"}
15
15
  ```
16
16
 
17
- In addition to allowing you to set the defaults for Paperclip has_attached_file now accepts a new option: default_asset_url
18
- When default_asset_url is passed in has_attached_file will determine the URL of the image through the Rails asset pipeline (making use of an asset host if you have set one for your Rails application). You can also make use of a Proc or lambda like so:
19
-
20
- ``` ruby
21
- class YourModel < ActiveRecord::Base
22
- has_attached_file :logo, default_asset_url: ->(attachment) { "#{attachment.instance.your_special_field}.png" }
23
- end
24
- ```
25
-
26
17
  Development
27
18
  -----------
28
19
  - Source hosted on [GitHub](https://github.com)
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Defaults
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -13,16 +13,6 @@ module Paperclip
13
13
  alias_method :has_attached_file_without_defaults, :has_attached_file
14
14
  def has_attached_file_with_defaults(name, options = {})
15
15
  paperclip_options = ::Rails.application.config.paperclip_defaults.merge(options)
16
- if paperclip_options[:default_asset_url]
17
- begin
18
- default_asset_url = paperclip_options[:default_asset_url]
19
- paperclip_options[:default_url] = ->(attachment) {ActionController::Base.new.view_context.asset_path(default_asset_url.respond_to?(:call) ? default_asset_url.call(attachment) : default_asset_url)}
20
- rescue StandardError => e
21
- ::Rails.logger.warn("Could not set default asset url for '#{paperclip_options[:default_asset_url]}'")
22
- end
23
-
24
- paperclip_options.delete(:default_asset_url)
25
- end
26
16
  has_attached_file_without_defaults(name, paperclip_options)
27
17
  end
28
18
  alias_method :has_attached_file, :has_attached_file_with_defaults
@@ -17,36 +17,6 @@ class TestPaperclipDefaults < MiniTest::Unit::TestCase
17
17
  assert_equal expect, model.attachment_definitions[:image1]
18
18
  end
19
19
 
20
- def test_default_asset_url_will_use_action_controller_view_context_to_decide_default_url
21
- ActionController::Base.stubs(:new).returns(mock('new_action_controller'))
22
- ActionController::Base.new.stubs(:view_context).returns(mock('view_context'))
23
- ActionController::Base.new.view_context.stubs(:asset_path).returns('http://www.example.com/unknown.png')
24
-
25
- model = Class.new(ActiveRecord::Base) do
26
- has_attached_file :image1, default_asset_url: "unknown.png"
27
- end
28
-
29
- expect = {validations: [], default_url: "http://www.example.com/unknown.png"}
30
- assert_equal [], model.attachment_definitions[:image1][:validations]
31
- assert_equal Proc, model.attachment_definitions[:image1][:default_url].class
32
- assert_equal "http://www.example.com/unknown.png", model.attachment_definitions[:image1][:default_url].call(nil)
33
- end
34
-
35
- def test_default_asset_url_with_proc_will_make_use_of_it_each_time
36
- ActionController::Base.stubs(:new).returns(mock('new_action_controller'))
37
- ActionController::Base.new.stubs(:view_context).returns(mock('view_context'))
38
- ActionController::Base.new.view_context.stubs(:asset_path).returns('http://www.example.com/unknown.png')
39
-
40
- model = Class.new(ActiveRecord::Base) do
41
- has_attached_file :image1, default_asset_url: ->(attachment){ "UNKNOWN.PNG".downcase }
42
- end
43
-
44
- expect = {validations: [], default_url: "http://www.example.com/unknown.png"}
45
- assert_equal [], model.attachment_definitions[:image1][:validations]
46
- assert_equal Proc, model.attachment_definitions[:image1][:default_url].class
47
- assert_equal "http://www.example.com/unknown.png", model.attachment_definitions[:image1][:default_url].call(nil)
48
- end
49
-
50
20
  def test_defaults_will_not_overwrite_explicit_options
51
21
  Rails.application.config.stubs(:paperclip_defaults).returns({storage: :fog})
52
22
  model = Class.new(ActiveRecord::Base) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-defaults
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-05 00:00:00.000000000 Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &22097060 !ruby/object:Gem::Requirement
16
+ requirement: &16356180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *22097060
24
+ version_requirements: *16356180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &21809720 !ruby/object:Gem::Requirement
27
+ requirement: &16351440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *21809720
35
+ version_requirements: *16351440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard
38
- requirement: &21531320 !ruby/object:Gem::Requirement
38
+ requirement: &16377320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21531320
46
+ version_requirements: *16377320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-bundler
49
- requirement: &19200420 !ruby/object:Gem::Requirement
49
+ requirement: &16390060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19200420
57
+ version_requirements: *16390060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-minitest
60
- requirement: &19069000 !ruby/object:Gem::Requirement
60
+ requirement: &16386140 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *19069000
68
+ version_requirements: *16386140
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rb-inotify
71
- requirement: &19078180 !ruby/object:Gem::Requirement
71
+ requirement: &16398480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *19078180
79
+ version_requirements: *16398480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: libnotify
82
- requirement: &19074720 !ruby/object:Gem::Requirement
82
+ requirement: &16411920 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *19074720
90
+ version_requirements: *16411920
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &19072900 !ruby/object:Gem::Requirement
93
+ requirement: &16410500 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *19072900
101
+ version_requirements: *16410500
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sqlite3
104
- requirement: &19071180 !ruby/object:Gem::Requirement
104
+ requirement: &16408780 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *19071180
112
+ version_requirements: *16408780
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rake
115
- requirement: &19084680 !ruby/object:Gem::Requirement
115
+ requirement: &16452340 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *19084680
123
+ version_requirements: *16452340
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: paperclip
126
- requirement: &19081500 !ruby/object:Gem::Requirement
126
+ requirement: &16462400 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *19081500
134
+ version_requirements: *16462400
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: activesupport
137
- requirement: &19094400 !ruby/object:Gem::Requirement
137
+ requirement: &16461160 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *19094400
145
+ version_requirements: *16461160
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rails
148
- requirement: &19092260 !ruby/object:Gem::Requirement
148
+ requirement: &16460260 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :runtime
155
155
  prerelease: false
156
- version_requirements: *19092260
156
+ version_requirements: *16460260
157
157
  description: Configurable application wide defaults for Paperclip
158
158
  email:
159
159
  - mark@socialreferral.com
@@ -195,10 +195,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: 4279530141429349155
198
+ hash: -487911157935510595
199
199
  requirements: []
200
200
  rubyforge_project:
201
- rubygems_version: 1.8.10
201
+ rubygems_version: 1.8.11
202
202
  signing_key:
203
203
  specification_version: 3
204
204
  summary: Configurable application wide defaults for Paperclip