carrierwave-meta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.rdoc +98 -0
- data/Rakefile +5 -0
- data/carrierwave-meta.gemspec +27 -0
- data/lib/carrierwave-meta.rb +4 -0
- data/lib/carrierwave-meta/meta.rb +63 -0
- data/lib/carrierwave-meta/model_delegate_attribute.rb +47 -0
- data/lib/carrierwave-meta/version.rb +5 -0
- data/spec/fixtures/big.jpg +0 -0
- data/spec/fixtures/big.zip +0 -0
- data/spec/fixtures/small.png +0 -0
- data/spec/modules/meta_spec.rb +114 -0
- data/spec/modules/model_delegate_attribute_spec.rb +69 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/schema.rb +15 -0
- data/spec/support/test_delegate_uploader.rb +43 -0
- data/spec/support/test_model.rb +24 -0
- data/spec/support/test_uploader.rb +20 -0
- metadata +180 -0
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
= carrierwave-meta
|
2
|
+
|
3
|
+
= Installation
|
4
|
+
|
5
|
+
Add the following line to your Gemfile:
|
6
|
+
gem 'carrierwave-meta'
|
7
|
+
|
8
|
+
= Usage example
|
9
|
+
|
10
|
+
class TestUploader < CarrierWave::Uploader::Base
|
11
|
+
include CarrierWave::RMagick
|
12
|
+
include CarrierWave::Meta
|
13
|
+
|
14
|
+
def store_dir
|
15
|
+
"tmp/store"
|
16
|
+
end
|
17
|
+
|
18
|
+
def cache_dir
|
19
|
+
"tmp/cache"
|
20
|
+
end
|
21
|
+
|
22
|
+
storage :file
|
23
|
+
|
24
|
+
process :store_meta
|
25
|
+
version :version do
|
26
|
+
process :resize_to_fill => [200, 200]
|
27
|
+
process :store_meta
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
file = File.open('test.jpg') # JPEG 500x300, 20000 bytes
|
32
|
+
uploader = TestUploader.new
|
33
|
+
uploader.store!(file)
|
34
|
+
|
35
|
+
uploader.width # 500
|
36
|
+
uploader.height # 300
|
37
|
+
uploader.image_size # [500, 300]
|
38
|
+
uploader.file_zie # 20000
|
39
|
+
uploader.content_type # "image/jpeg"
|
40
|
+
|
41
|
+
uploader.version.width # 200
|
42
|
+
uploader.version.height # 200
|
43
|
+
uploader.version.image_size # [200, 200]
|
44
|
+
uploader.version.file_zie # less than 20000
|
45
|
+
uploader.version.content_type # "image/jpeg"
|
46
|
+
|
47
|
+
= Saving values to database
|
48
|
+
|
49
|
+
class TestModel
|
50
|
+
attr_accessor :image_width
|
51
|
+
attr_accessor :image_height
|
52
|
+
attr_accessor :image_image_size
|
53
|
+
attr_accessor :image_content_type
|
54
|
+
attr_accessor :image_file_size
|
55
|
+
|
56
|
+
attr_accessor :image_version_width
|
57
|
+
attr_accessor :image_version_height
|
58
|
+
attr_accessor :image_version_image_size
|
59
|
+
attr_accessor :image_version_content_type
|
60
|
+
attr_accessor :image_version_file_size
|
61
|
+
end
|
62
|
+
|
63
|
+
file = File.open('test.jpg')
|
64
|
+
model = TestModel.new
|
65
|
+
uploader = TestUploader.new(model, :image)
|
66
|
+
uploader.store!(file)
|
67
|
+
|
68
|
+
uploader.width # 500
|
69
|
+
model.image_width # 500
|
70
|
+
model.image_height # 300
|
71
|
+
...
|
72
|
+
|
73
|
+
When columns are available in the model instance, metadata is stored in that columns.
|
74
|
+
|
75
|
+
= Behind the scenes
|
76
|
+
|
77
|
+
After the file is retrieved from store metadata is recalculated for it unless uploader has
|
78
|
+
attached model instance.
|
79
|
+
|
80
|
+
uploader = TestUploader.new
|
81
|
+
uploader.retrieve_from_store!('test.jpg')
|
82
|
+
|
83
|
+
uploader.version.width # 200
|
84
|
+
|
85
|
+
So, if you are storing width and height in database column and then you decided to store
|
86
|
+
content type.
|
87
|
+
|
88
|
+
Uploader tries to retrieve metadata from a model's column first.
|
89
|
+
|
90
|
+
= Integrating CarrierWave & JCrop using carrierwave-meta
|
91
|
+
|
92
|
+
|
93
|
+
= TODO
|
94
|
+
|
95
|
+
1. I do not know how it would work with S3 and other remote storages. Should be tested.
|
96
|
+
2. Write integration guide for JCrop.
|
97
|
+
3. A notice about content-type.
|
98
|
+
4. It works now only with RMagick. Add support for other image libraries. It's easy.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "carrierwave-meta/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "carrierwave-meta"
|
7
|
+
s.version = Carrierwave::Meta::VERSION
|
8
|
+
s.authors = ["Victor Sokolov"]
|
9
|
+
s.email = ["gzigzigzi@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/gzigzigzeo/carrierwave-meta"
|
11
|
+
s.summary = %q{}
|
12
|
+
s.description = %q{}
|
13
|
+
|
14
|
+
s.rubyforge_project = "carrierwave-meta"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency(%q<carrierwave>, [">= 0.5.7"])
|
22
|
+
s.add_dependency(%q<activesupport>, [">= 3.0"])
|
23
|
+
s.add_development_dependency(%q<rspec-rails>, ">= 2.6")
|
24
|
+
s.add_development_dependency(%q<sqlite3-ruby>)
|
25
|
+
s.add_development_dependency(%q<rmagick>)
|
26
|
+
s.add_development_dependency(%q<mime-types>)
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Meta
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include CarrierWave::ModelDelegateAttribute
|
7
|
+
include CarrierWave::MimeTypes
|
8
|
+
|
9
|
+
set_content_type(true)
|
10
|
+
|
11
|
+
after :retrieve_from_cache, :set_content_type
|
12
|
+
after :retrieve_from_cache, :call_store_meta
|
13
|
+
after :retrieve_from_store, :set_content_type
|
14
|
+
after :retrieve_from_store, :call_store_meta
|
15
|
+
|
16
|
+
model_delegate_attribute :content_type, ''
|
17
|
+
model_delegate_attribute :file_size, 0
|
18
|
+
model_delegate_attribute :image_size, []
|
19
|
+
model_delegate_attribute :width, 0
|
20
|
+
model_delegate_attribute :height, 0
|
21
|
+
end
|
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
|
+
private
|
41
|
+
def call_store_meta(file = nil)
|
42
|
+
# Re-retrieve metadata for a file only if model is not present.
|
43
|
+
store_meta if self.model.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_dimensions
|
47
|
+
[].tap do |size|
|
48
|
+
if self.file.content_type =~ /image/
|
49
|
+
manipulate! do |img|
|
50
|
+
if img.is_a?(::Magick::Image)
|
51
|
+
size << img.columns
|
52
|
+
size << img.rows
|
53
|
+
else
|
54
|
+
raise "Only RMagick is supported yet. Fork and update it."
|
55
|
+
end
|
56
|
+
img
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module ModelDelegateAttribute
|
3
|
+
extend ::ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def model_delegate_attribute(attribute, default = nil)
|
7
|
+
attr_accessor attribute
|
8
|
+
|
9
|
+
before :remove, :"reset_#{attribute}"
|
10
|
+
|
11
|
+
var_name = :"@#{attribute}"
|
12
|
+
|
13
|
+
define_method :"#{attribute}" do
|
14
|
+
model_accessor = model_getter_name(attribute)
|
15
|
+
value = instance_variable_get(var_name)
|
16
|
+
value ||= self.model.send(model_accessor) if self.model.present? && self.model.respond_to?(model_accessor)
|
17
|
+
value ||= default
|
18
|
+
instance_variable_set(var_name, value)
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method :"#{attribute}=" do |value|
|
22
|
+
model_accessor = model_getter_name(attribute)
|
23
|
+
instance_variable_set(var_name, value)
|
24
|
+
if self.model.present? && self.model.respond_to?(:"#{model_accessor}=") && !self.model.destroyed?
|
25
|
+
self.model.send(:"#{model_accessor}=", value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
define_method :"reset_#{attribute}" do
|
30
|
+
self.send(:"#{attribute}=", default)
|
31
|
+
send(:"#{attribute}=", default)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
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
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mime/types'
|
3
|
+
|
4
|
+
describe TestUploader do
|
5
|
+
ORIGINAL_SIZE = [600, 277]
|
6
|
+
VERSION_SIZE = [200, 200]
|
7
|
+
|
8
|
+
let(:file) { File.open("spec/fixtures/big.jpg") }
|
9
|
+
let(:file_name) { File.basename(file.path) }
|
10
|
+
let(:obj) { TestModel.new }
|
11
|
+
|
12
|
+
def uploader_values_are_correct(uploader)
|
13
|
+
uploader.width.should eq(ORIGINAL_SIZE[0])
|
14
|
+
uploader.height.should eq(ORIGINAL_SIZE[1])
|
15
|
+
uploader.image_size.should eq(ORIGINAL_SIZE)
|
16
|
+
uploader.content_type.should eq(Mime::Types.type_for(file_name).first.to_s)
|
17
|
+
uploader.file_size.should_not be_blank
|
18
|
+
|
19
|
+
uploader.version.width.should eq(VERSION_SIZE[0])
|
20
|
+
uploader.version.height.should eq(VERSION_SIZE[1])
|
21
|
+
uploader.version.image_size.should eq(VERSION_SIZE)
|
22
|
+
uploader.version.content_type.should eq(Mime::Types.type_for(file_name).first.to_s)
|
23
|
+
uploader.version.file_size.should_not be_blank
|
24
|
+
end
|
25
|
+
|
26
|
+
def obj_values_are_correct(obj)
|
27
|
+
obj.image_width.should eq(ORIGINAL_SIZE[0])
|
28
|
+
obj.image_height.should eq(ORIGINAL_SIZE[1])
|
29
|
+
obj.image_image_size.should eq(ORIGINAL_SIZE)
|
30
|
+
obj.image_content_type.should eq(MIME::Types.type_for(file_name).first.to_s)
|
31
|
+
obj.image_file_size.should_not be_blank
|
32
|
+
|
33
|
+
obj.image_version_width.should eq(VERSION_SIZE[0])
|
34
|
+
obj.image_version_height.should eq(VERSION_SIZE[1])
|
35
|
+
obj.image_version_image_size.should eq(VERSION_SIZE)
|
36
|
+
obj.image_version_content_type.should eq(MIME::Types.type_for(file_name).first.to_s)
|
37
|
+
obj.image_version_file_size.should_not be_blank
|
38
|
+
end
|
39
|
+
|
40
|
+
def uploader_values_are_correct(obj)
|
41
|
+
obj.width.should eq(ORIGINAL_SIZE[0])
|
42
|
+
obj.height.should eq(ORIGINAL_SIZE[1])
|
43
|
+
end
|
44
|
+
|
45
|
+
context "detached uploader" do
|
46
|
+
it "stores metadata after cache!" do
|
47
|
+
uploader = TestUploader.new
|
48
|
+
uploader.cache!(file)
|
49
|
+
uploader_values_are_correct(uploader)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "stores metadata after store!" do
|
53
|
+
uploader = TestUploader.new
|
54
|
+
uploader.store!(file)
|
55
|
+
uploader_values_are_correct(uploader)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "has metadata after cache!/retrieve_from_cache!" do
|
59
|
+
uploader = TestUploader.new
|
60
|
+
uploader.cache!(file)
|
61
|
+
cache_name = uploader.cache_name
|
62
|
+
|
63
|
+
uploader = TestUploader.new
|
64
|
+
uploader.retrieve_from_cache!(cache_name)
|
65
|
+
uploader_values_are_correct(uploader)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has metadata after store!/retrieve_from_store!" do
|
69
|
+
uploader = TestUploader.new
|
70
|
+
uploader.store!(file)
|
71
|
+
uploader_values_are_correct(uploader)
|
72
|
+
|
73
|
+
uploader = TestUploader.new
|
74
|
+
uploader.retrieve_from_store!(File.basename(file.path))
|
75
|
+
uploader_values_are_correct(uploader)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "attached uploader" do
|
80
|
+
it "stores metadata after cache!" do
|
81
|
+
uploader = TestUploader.new(obj, :image)
|
82
|
+
uploader.cache!(file)
|
83
|
+
uploader_values_are_correct(uploader)
|
84
|
+
obj_values_are_correct(obj)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "stores metadata after store!" do
|
88
|
+
uploader = TestUploader.new(obj, :image)
|
89
|
+
uploader.store!(file)
|
90
|
+
uploader_values_are_correct(uploader)
|
91
|
+
obj_values_are_correct(obj)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "has metadata after cache!/retrieve_from_cache!" do
|
95
|
+
uploader = TestUploader.new(obj, :image)
|
96
|
+
uploader.cache!(file)
|
97
|
+
cache_name = uploader.cache_name
|
98
|
+
|
99
|
+
uploader = TestUploader.new(obj, :image)
|
100
|
+
uploader.retrieve_from_cache!(cache_name)
|
101
|
+
uploader_values_are_correct(uploader)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "has metadata after store!/retrieve_from_store!" do
|
105
|
+
uploader = TestUploader.new(obj, :image)
|
106
|
+
uploader.store!(file)
|
107
|
+
uploader_values_are_correct(uploader)
|
108
|
+
|
109
|
+
uploader = TestUploader.new(obj, :image)
|
110
|
+
uploader.retrieve_from_store!(File.basename(file.path))
|
111
|
+
uploader_values_are_correct(uploader)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TestDelegateUploader do
|
4
|
+
let(:values) { subject.class::VALUES }
|
5
|
+
let(:default_values) { subject.class::DEFAULT_VALUES }
|
6
|
+
let(:file) { File.open("spec/fixtures/big.jpg") }
|
7
|
+
let(:obj) { TestModel.new }
|
8
|
+
|
9
|
+
before do
|
10
|
+
obj.destroyed = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def uploader_values_are_correct(uploader)
|
14
|
+
uploader.x.should eq(values[:x])
|
15
|
+
uploader.dimensions.should eq(values[:dimensions])
|
16
|
+
uploader.version.x.should eq(values[:version_x])
|
17
|
+
uploader.version.dimensions.should eq(values[:version_dimensions])
|
18
|
+
end
|
19
|
+
|
20
|
+
def obj_values_are_correct(obj)
|
21
|
+
obj.image_x.should eq(values[:x])
|
22
|
+
obj.image_dimensions.should eq(values[:dimensions])
|
23
|
+
obj.image_version_x.should eq(values[:version_x])
|
24
|
+
obj.image_version_dimensions.should eq(values[:version_dimensions])
|
25
|
+
end
|
26
|
+
|
27
|
+
def uploader_values_are_default(obj)
|
28
|
+
obj.x.should eq(default_values[:x])
|
29
|
+
obj.dimensions.should eq(default_values[:dimensions])
|
30
|
+
obj.version.x.should eq(default_values[:x])
|
31
|
+
obj.version.dimensions.should eq(default_values[:dimensions])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "model receives values after process done" do
|
35
|
+
uploader = TestDelegateUploader.new(obj, :image)
|
36
|
+
uploader.cache!(file)
|
37
|
+
|
38
|
+
uploader_values_are_correct(uploader)
|
39
|
+
obj_values_are_correct(obj)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "resets values to default after file is removed" do
|
43
|
+
uploader = TestDelegateUploader.new(obj, :image)
|
44
|
+
uploader.store!(file)
|
45
|
+
|
46
|
+
uploader_values_are_correct(uploader)
|
47
|
+
|
48
|
+
# CarrierWave's file is removed in after_destroy callback. Model attributes are freezed after destroy.
|
49
|
+
# Let mock this case.
|
50
|
+
obj.image_x.freeze
|
51
|
+
obj.destroyed = true
|
52
|
+
uploader.remove!
|
53
|
+
|
54
|
+
uploader_values_are_default(uploader)
|
55
|
+
obj_values_are_correct(obj)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "tries to receive value from a model when file was not processed at this time" do
|
59
|
+
uploader = TestDelegateUploader.new(obj, :image)
|
60
|
+
uploader.store!(file)
|
61
|
+
|
62
|
+
uploader_values_are_correct(uploader)
|
63
|
+
|
64
|
+
uploader = TestDelegateUploader.new(obj, :image)
|
65
|
+
uploader.retrieve_from_store!(File.basename(file.path))
|
66
|
+
|
67
|
+
obj_values_are_correct(obj)
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
Bundler.require
|
7
|
+
rescue Bundler::GemNotFound
|
8
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
9
|
+
"Did you run `bundle install`?"
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'mime/types'
|
13
|
+
require 'carrierwave'
|
14
|
+
require 'carrierwave-meta'
|
15
|
+
require 'support/test_delegate_uploader'
|
16
|
+
require 'support/test_uploader'
|
17
|
+
require 'support/test_model'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.before do
|
21
|
+
FileUtils.rm_rf('tmp')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
create_table "test_models", :force => true do |t|
|
3
|
+
t.string :image
|
4
|
+
|
5
|
+
t.integer :image_width
|
6
|
+
t.integer :image_height
|
7
|
+
t.string :image_content_type
|
8
|
+
t.integer :image_file_size
|
9
|
+
|
10
|
+
t.integer :image_version_width
|
11
|
+
t.integer :image_version_height
|
12
|
+
t.integer :image_version_file_size
|
13
|
+
t.string :image_version_content_type
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class TestDelegateUploader < CarrierWave::Uploader::Base
|
2
|
+
VALUES = {
|
3
|
+
:x => 5,
|
4
|
+
:version_x => 10,
|
5
|
+
:dimensions => [1, 1],
|
6
|
+
:version_dimensions => [2, 2]
|
7
|
+
}
|
8
|
+
|
9
|
+
DEFAULT_VALUES = {
|
10
|
+
:x => 0,
|
11
|
+
:dimensions => []
|
12
|
+
}
|
13
|
+
|
14
|
+
storage :file
|
15
|
+
|
16
|
+
def store_dir
|
17
|
+
"tmp/store"
|
18
|
+
end
|
19
|
+
|
20
|
+
def cache_dir
|
21
|
+
"tmp/cache"
|
22
|
+
end
|
23
|
+
|
24
|
+
include CarrierWave::ModelDelegateAttribute
|
25
|
+
|
26
|
+
model_delegate_attribute :x, DEFAULT_VALUES[:x]
|
27
|
+
model_delegate_attribute :dimensions, DEFAULT_VALUES[:dimensions]
|
28
|
+
|
29
|
+
process :set_values
|
30
|
+
version :version do
|
31
|
+
process :set_values_for_version
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_values
|
35
|
+
self.x = VALUES[:x]
|
36
|
+
self.dimensions = VALUES[:dimensions]
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_values_for_version
|
40
|
+
self.x = VALUES[:version_x]
|
41
|
+
self.dimensions = VALUES[:version_dimensions]
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class TestModel
|
2
|
+
attr_accessor :image_x
|
3
|
+
attr_accessor :image_version_x
|
4
|
+
attr_accessor :image_dimensions
|
5
|
+
attr_accessor :image_version_dimensions
|
6
|
+
|
7
|
+
attr_accessor :image_width
|
8
|
+
attr_accessor :image_height
|
9
|
+
attr_accessor :image_image_size
|
10
|
+
attr_accessor :image_content_type
|
11
|
+
attr_accessor :image_file_size
|
12
|
+
|
13
|
+
attr_accessor :image_version_width
|
14
|
+
attr_accessor :image_version_height
|
15
|
+
attr_accessor :image_version_image_size
|
16
|
+
attr_accessor :image_version_content_type
|
17
|
+
attr_accessor :image_version_file_size
|
18
|
+
|
19
|
+
attr_accessor :destroyed
|
20
|
+
|
21
|
+
def destroyed?
|
22
|
+
destroyed
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class TestUploader < CarrierWave::Uploader::Base
|
2
|
+
include CarrierWave::RMagick
|
3
|
+
include CarrierWave::Meta
|
4
|
+
|
5
|
+
def store_dir
|
6
|
+
"tmp/store"
|
7
|
+
end
|
8
|
+
|
9
|
+
def cache_dir
|
10
|
+
"tmp/cache"
|
11
|
+
end
|
12
|
+
|
13
|
+
storage :file
|
14
|
+
|
15
|
+
process :store_meta
|
16
|
+
version :version do
|
17
|
+
process :resize_to_fill => [200, 200]
|
18
|
+
process :store_meta
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-meta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Victor Sokolov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
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
|
33
|
+
version: 0.5.7
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
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"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec-rails
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 15
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 6
|
63
|
+
version: "2.6"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: sqlite3-ruby
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rmagick
|
82
|
+
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"
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: mime-types
|
96
|
+
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"
|
106
|
+
type: :development
|
107
|
+
version_requirements: *id006
|
108
|
+
description: ""
|
109
|
+
email:
|
110
|
+
- gzigzigzi@gmail.com
|
111
|
+
executables: []
|
112
|
+
|
113
|
+
extensions: []
|
114
|
+
|
115
|
+
extra_rdoc_files: []
|
116
|
+
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- README.rdoc
|
121
|
+
- Rakefile
|
122
|
+
- carrierwave-meta.gemspec
|
123
|
+
- lib/carrierwave-meta.rb
|
124
|
+
- lib/carrierwave-meta/meta.rb
|
125
|
+
- lib/carrierwave-meta/model_delegate_attribute.rb
|
126
|
+
- lib/carrierwave-meta/version.rb
|
127
|
+
- spec/fixtures/big.jpg
|
128
|
+
- spec/fixtures/big.zip
|
129
|
+
- spec/fixtures/small.png
|
130
|
+
- spec/modules/meta_spec.rb
|
131
|
+
- spec/modules/model_delegate_attribute_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/schema.rb
|
134
|
+
- spec/support/test_delegate_uploader.rb
|
135
|
+
- spec/support/test_model.rb
|
136
|
+
- spec/support/test_uploader.rb
|
137
|
+
homepage: http://github.com/gzigzigzeo/carrierwave-meta
|
138
|
+
licenses: []
|
139
|
+
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
hash: 3
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
version: "0"
|
163
|
+
requirements: []
|
164
|
+
|
165
|
+
rubyforge_project: carrierwave-meta
|
166
|
+
rubygems_version: 1.8.6
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: ""
|
170
|
+
test_files:
|
171
|
+
- spec/fixtures/big.jpg
|
172
|
+
- spec/fixtures/big.zip
|
173
|
+
- spec/fixtures/small.png
|
174
|
+
- spec/modules/meta_spec.rb
|
175
|
+
- spec/modules/model_delegate_attribute_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/support/schema.rb
|
178
|
+
- spec/support/test_delegate_uploader.rb
|
179
|
+
- spec/support/test_model.rb
|
180
|
+
- spec/support/test_uploader.rb
|