grip 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/grip.gemspec +1 -1
- data/lib/grip.rb +14 -4
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/grip.gemspec
CHANGED
data/lib/grip.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'mongo/gridfs'
|
2
2
|
require 'mime/types'
|
3
3
|
require 'tempfile'
|
4
|
-
require '
|
4
|
+
require 'miso'
|
5
5
|
|
6
6
|
module Grip
|
7
7
|
def self.included(base)
|
@@ -59,7 +59,7 @@ module Grip
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def update_attachment_attributes! name, file, is_version = false
|
62
|
-
raise Grip::InvalidFileException unless (file.is_a?(File) || file.is_a?(Tempfile))
|
62
|
+
raise Grip::InvalidFileException unless (file.is_a?(File) || file.is_a?(Tempfile) || file.is_a?(Miso::Image))
|
63
63
|
|
64
64
|
self["#{name}_size"] = File.size(file)
|
65
65
|
self["#{name}_name"] = File.basename(file.path)
|
@@ -86,12 +86,22 @@ module Grip
|
|
86
86
|
|
87
87
|
unless opts[:versions].nil?
|
88
88
|
opts[:versions].each do |version,dimensions|
|
89
|
-
|
90
|
-
|
89
|
+
|
90
|
+
tmp = Tempfile.new("#{attr_name}_#{version}")
|
91
|
+
image = Miso::Image.new(opts[:file].path)
|
92
|
+
|
93
|
+
image.crop(dimensions[:width], dimensions[:height]) if opts[:crop]
|
94
|
+
image.fit(dimensions[:width], dimensions[:height]) unless opts[:crop]
|
95
|
+
|
96
|
+
image.write(tmp.path)
|
97
|
+
|
98
|
+
# update <name>_<version> attrs and assign the file
|
91
99
|
send("#{attr_name}_#{version}=", tmp)
|
100
|
+
|
92
101
|
GridFS::GridStore.open(self.class.database, self["#{attr_name}_#{version}_path"], 'w', :content_type => self["#{attr_name}_content_type"]) do |f|
|
93
102
|
f.write tmp.read
|
94
103
|
end
|
104
|
+
|
95
105
|
end
|
96
106
|
save_to_collection
|
97
107
|
end
|