carrierwave-meta 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
-
20
+
21
21
  s.add_dependency(%q<carrierwave>, [">= 0.5.7"])
22
- s.add_dependency(%q<activesupport>, [">= 3.0"])
22
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
23
23
  s.add_dependency(%q<mime-types>)
24
24
  s.add_development_dependency(%q<rspec-rails>, ">= 2.6")
25
- s.add_development_dependency(%q<sqlite3-ruby>)
25
+ s.add_development_dependency(%q<sqlite3-ruby>)
26
26
  s.add_development_dependency(%q<rmagick>)
27
27
  s.add_development_dependency(%q<mini_magick>)
28
28
  s.add_development_dependency(%q<mime-types>)
29
- end
29
+ end
@@ -7,7 +7,7 @@ module CarrierWave
7
7
  include CarrierWave::MimeTypes
8
8
 
9
9
  set_content_type(true)
10
-
10
+
11
11
  after :retrieve_from_cache, :set_content_type
12
12
  after :retrieve_from_cache, :call_store_meta
13
13
  after :retrieve_from_store, :set_content_type
@@ -20,51 +20,50 @@ module CarrierWave
20
20
  model_delegate_attribute :height, 0
21
21
  end
22
22
 
23
- module InstanceMethods
24
- def store_meta
25
- if self.file.present?
26
- dimensions = get_dimensions
27
- width, height = dimensions
28
- self.content_type = self.file.content_type
29
- self.file_size = self.file.size
30
- self.image_size = dimensions
31
- self.width = width
32
- self.height = height
33
- end
34
- end
35
-
36
- def set_content_type(file = nil)
37
- set_content_type(true)
38
- end
39
-
40
- def image_size_s
41
- image_size.join('x')
23
+ def store_meta
24
+ if self.file.present?
25
+ dimensions = get_dimensions
26
+ width, height = dimensions
27
+ self.content_type = self.file.content_type
28
+ self.file_size = self.file.size
29
+ self.image_size = dimensions
30
+ self.width = width
31
+ self.height = height
42
32
  end
43
-
44
- private
45
- def call_store_meta(file = nil)
46
- # Re-retrieve metadata for a file only if model is not present OR model is not saved.
47
- store_meta if self.model.nil? || (self.model.respond_to?(:new_record?) && self.model.new_record?)
48
- end
49
-
50
- def get_dimensions
51
- [].tap do |size|
52
- if self.file.content_type =~ /image/
53
- manipulate! do |img|
54
- if defined?(::Magick::Image) && img.is_a?(::Magick::Image)
55
- size << img.columns
56
- size << img.rows
57
- elsif defined?(::MiniMagick::Image) && img.is_a?(::MiniMagick::Image)
58
- size << img["width"]
59
- size << img["height"]
60
- else
61
- raise "Only RMagick is supported yet. Fork and update it."
62
- end
63
- img
33
+ end
34
+
35
+ def set_content_type(file = nil)
36
+ set_content_type(true)
37
+ end
38
+
39
+ def image_size_s
40
+ image_size.join('x')
41
+ end
42
+
43
+ private
44
+ def call_store_meta(file = nil)
45
+ # Re-retrieve metadata for a file only if model is not present OR model is not saved.
46
+ store_meta if self.model.nil? || (self.model.respond_to?(:new_record?) && self.model.new_record?)
47
+ end
48
+
49
+ def get_dimensions
50
+ [].tap do |size|
51
+ if self.file.content_type =~ /image/
52
+ manipulate! do |img|
53
+ if defined?(::Magick::Image) && img.is_a?(::Magick::Image)
54
+ size << img.columns
55
+ size << img.rows
56
+ elsif defined?(::MiniMagick::Image) && img.is_a?(::MiniMagick::Image)
57
+ size << img["width"]
58
+ size << img["height"]
59
+ else
60
+ raise "Only RMagick & MiniMagick are supported yet. Fork and update it."
64
61
  end
62
+ img
65
63
  end
66
64
  end
67
- end
65
+ end
66
+ rescue CarrierWave::ProcessingError
68
67
  end
69
68
  end
70
69
  end
@@ -33,15 +33,13 @@ module CarrierWave
33
33
  end
34
34
  end
35
35
 
36
- module InstanceMethods
37
- private
38
- def model_getter_name(attribute)
39
- name = []
40
- name << mounted_as if mounted_as.present?
41
- name << version_name if version_name.present?
42
- name << attribute
43
- name.join('_')
44
- end
36
+ private
37
+ def model_getter_name(attribute)
38
+ name = []
39
+ name << mounted_as if mounted_as.present?
40
+ name << version_name if version_name.present?
41
+ name << attribute
42
+ name.join('_')
45
43
  end
46
44
  end
47
45
  end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Meta
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
Binary file
@@ -5,9 +5,10 @@ describe TestUploader do
5
5
  ORIGINAL_SIZE = [600, 277]
6
6
  VERSION_SIZE = [200, 200]
7
7
 
8
- let(:file) { File.open("spec/fixtures/big.jpg") }
8
+ let(:file) { File.open("spec/fixtures/big.jpg") }
9
+ let(:corrupted_file) { File.open("spec/fixtures/corrupted.bmp") }
9
10
  let(:file_name) { File.basename(file.path) }
10
- let(:obj) { TestModel.new }
11
+ let(:obj) { TestModel.new }
11
12
 
12
13
  def uploader_values_are_correct(uploader)
13
14
  uploader.width.should eq(ORIGINAL_SIZE[0])
@@ -22,7 +23,7 @@ describe TestUploader do
22
23
  uploader.version.image_size.should eq(VERSION_SIZE)
23
24
  uploader.version.content_type.should eq(MIME::Types.type_for(file_name).first.to_s)
24
25
  uploader.version.file_size.should_not be_blank
25
- uploader.version.image_size_s.should eq(VERSION_SIZE.join('x'))
26
+ uploader.version.image_size_s.should eq(VERSION_SIZE.join('x'))
26
27
  end
27
28
 
28
29
  def obj_values_are_correct(obj)
@@ -45,13 +46,13 @@ describe TestUploader do
45
46
  uploader.cache!(file)
46
47
  uploader_values_are_correct(uploader)
47
48
  end
48
-
49
+
49
50
  it "stores metadata after store!" do
50
51
  uploader = TestUploader.new
51
52
  uploader.store!(file)
52
53
  uploader_values_are_correct(uploader)
53
54
  end
54
-
55
+
55
56
  it "has metadata after cache!/retrieve_from_cache!" do
56
57
  uploader = TestUploader.new
57
58
  uploader.cache!(file)
@@ -61,16 +62,16 @@ describe TestUploader do
61
62
  uploader.retrieve_from_cache!(cache_name)
62
63
  uploader_values_are_correct(uploader)
63
64
  end
64
-
65
+
65
66
  it "has metadata after store!/retrieve_from_store!" do
66
67
  uploader = TestUploader.new
67
68
  uploader.store!(file)
68
69
  uploader_values_are_correct(uploader)
69
-
70
+
70
71
  uploader = TestUploader.new
71
72
  uploader.retrieve_from_store!(File.basename(file.path))
72
- uploader_values_are_correct(uploader)
73
- end
73
+ uploader_values_are_correct(uploader)
74
+ end
74
75
  end
75
76
 
76
77
  context "attached uploader" do
@@ -80,14 +81,14 @@ describe TestUploader do
80
81
  uploader_values_are_correct(uploader)
81
82
  obj_values_are_correct(obj)
82
83
  end
83
-
84
+
84
85
  it "stores metadata after store!" do
85
86
  uploader = TestUploader.new(obj, :image)
86
87
  uploader.store!(file)
87
88
  uploader_values_are_correct(uploader)
88
- obj_values_are_correct(obj)
89
+ obj_values_are_correct(obj)
89
90
  end
90
-
91
+
91
92
  it "has metadata after cache!/retrieve_from_cache!" do
92
93
  uploader = TestUploader.new(obj, :image)
93
94
  uploader.cache!(file)
@@ -97,15 +98,22 @@ describe TestUploader do
97
98
  uploader.retrieve_from_cache!(cache_name)
98
99
  uploader_values_are_correct(uploader)
99
100
  end
100
-
101
+
101
102
  it "has metadata after store!/retrieve_from_store!" do
102
103
  uploader = TestUploader.new(obj, :image)
103
104
  uploader.store!(file)
104
105
  uploader_values_are_correct(uploader)
105
-
106
+
106
107
  uploader = TestUploader.new(obj, :image)
107
108
  uploader.retrieve_from_store!(File.basename(file.path))
108
- uploader_values_are_correct(uploader)
109
- end
109
+ uploader_values_are_correct(uploader)
110
+ end
111
+ end
112
+
113
+ context "when file is corrupted/can not be processed" do
114
+ it "passes without exceptions" do
115
+ uploader = TestBlankUploader.new(obj, :image)
116
+ proc { uploader.store!(corrupted_file) }.should_not raise_error
117
+ end
110
118
  end
111
119
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
3
3
  begin
4
4
  require "bundler"
5
5
  Bundler.setup
6
- Bundler.require
6
+ Bundler.require
7
7
  rescue Bundler::GemNotFound
8
8
  raise RuntimeError, "Bundler couldn't find some gems." +
9
9
  "Did you run `bundle install`?"
@@ -15,6 +15,7 @@ require 'mime/types'
15
15
  require 'carrierwave'
16
16
  require 'carrierwave-meta'
17
17
  require 'support/test_delegate_uploader'
18
+ require 'support/test_blank_uploader'
18
19
  require 'support/test_uploader'
19
20
  require 'support/test_model'
20
21
 
@@ -0,0 +1,19 @@
1
+ class TestBlankUploader < CarrierWave::Uploader::Base
2
+ if PROCESSOR == :mini_magick
3
+ include CarrierWave::MiniMagick
4
+ else
5
+ include CarrierWave::RMagick
6
+ end
7
+ include CarrierWave::Meta
8
+
9
+ def store_dir
10
+ "tmp/store"
11
+ end
12
+
13
+ def cache_dir
14
+ "tmp/cache"
15
+ end
16
+
17
+ storage :file
18
+ process :store_meta
19
+ end
metadata CHANGED
@@ -1,148 +1,151 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-meta
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Victor Sokolov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-11 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: carrierwave
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 5
29
- segments:
30
- - 0
31
- - 5
32
- - 7
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.5.7
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activesupport
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: mime-types
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mime-types
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :runtime
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: rspec-rails
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 15
74
- segments:
75
- - 2
76
- - 6
77
- version: "2.6"
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '2.6'
78
70
  type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: sqlite3-ruby
82
71
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '2.6'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3-ruby
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
92
86
  type: :development
93
- version_requirements: *id005
94
- - !ruby/object:Gem::Dependency
95
- name: rmagick
96
87
  prerelease: false
97
- requirement: &id006 !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rmagick
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
106
102
  type: :development
107
- version_requirements: *id006
108
- - !ruby/object:Gem::Dependency
109
- name: mini_magick
110
103
  prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
112
- none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mini_magick
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
120
118
  type: :development
121
- version_requirements: *id007
122
- - !ruby/object:Gem::Dependency
123
- name: mime-types
124
119
  prerelease: false
125
- requirement: &id008 !ruby/object:Gem::Requirement
126
- none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: mime-types
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
134
  type: :development
135
- version_requirements: *id008
136
- description: ""
137
- email:
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: ''
143
+ email:
138
144
  - gzigzigzi@gmail.com
139
145
  executables: []
140
-
141
146
  extensions: []
142
-
143
147
  extra_rdoc_files: []
144
-
145
- files:
148
+ files:
146
149
  - .gitignore
147
150
  - Gemfile
148
151
  - README.rdoc
@@ -154,55 +157,44 @@ files:
154
157
  - lib/carrierwave-meta/version.rb
155
158
  - spec/fixtures/big.jpg
156
159
  - spec/fixtures/big.zip
160
+ - spec/fixtures/corrupted.bmp
157
161
  - spec/fixtures/small.png
158
162
  - spec/modules/meta_spec.rb
159
163
  - spec/modules/model_delegate_attribute_spec.rb
160
164
  - spec/spec_helper.rb
161
165
  - spec/support/schema.rb
166
+ - spec/support/test_blank_uploader.rb
162
167
  - spec/support/test_delegate_uploader.rb
163
168
  - spec/support/test_model.rb
164
169
  - spec/support/test_uploader.rb
165
170
  homepage: http://github.com/gzigzigzeo/carrierwave-meta
166
171
  licenses: []
167
-
168
172
  post_install_message:
169
173
  rdoc_options: []
170
-
171
- require_paths:
174
+ require_paths:
172
175
  - lib
173
- required_ruby_version: !ruby/object:Gem::Requirement
176
+ required_ruby_version: !ruby/object:Gem::Requirement
174
177
  none: false
175
- requirements:
176
- - - ">="
177
- - !ruby/object:Gem::Version
178
- hash: 3
179
- segments:
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ segments:
180
183
  - 0
181
- version: "0"
182
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ hash: -518299106991217917
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
186
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ segments:
189
192
  - 0
190
- version: "0"
193
+ hash: -518299106991217917
191
194
  requirements: []
192
-
193
195
  rubyforge_project: carrierwave-meta
194
- rubygems_version: 1.8.11
196
+ rubygems_version: 1.8.24
195
197
  signing_key:
196
198
  specification_version: 3
197
- summary: ""
198
- test_files:
199
- - spec/fixtures/big.jpg
200
- - spec/fixtures/big.zip
201
- - spec/fixtures/small.png
202
- - spec/modules/meta_spec.rb
203
- - spec/modules/model_delegate_attribute_spec.rb
204
- - spec/spec_helper.rb
205
- - spec/support/schema.rb
206
- - spec/support/test_delegate_uploader.rb
207
- - spec/support/test_model.rb
208
- - spec/support/test_uploader.rb
199
+ summary: ''
200
+ test_files: []