grip 0.4.2 → 0.4.3

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.
data/README.rdoc CHANGED
@@ -15,8 +15,16 @@ The grip gem is hosted on gemcutter.org:
15
15
  include MongoMapper::Document
16
16
  include Grip
17
17
 
18
- has_grid_attachment :image
18
+ has_grid_attachment :image, :resize => {:width=>50,:height=>50}
19
19
  has_grid_attachment :pdf
20
+
21
+ # Hook for resizing or whatever gets you there.
22
+ # any specified options are passed back to you
23
+ # at this point.
24
+ # Just return the file when you're done.
25
+ def grip_process_file opts
26
+ opts[:file]
27
+ end
20
28
  end
21
29
 
22
30
  image = File.open('foo.png', 'r')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/grip.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grip}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["twoism", "jnunemaker"]
data/lib/grip.rb CHANGED
@@ -27,9 +27,9 @@ module Grip
27
27
  end
28
28
 
29
29
  module ClassMethods
30
- def has_grid_attachment(name)
30
+ def has_grid_attachment(name,opts={})
31
31
  write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
32
- attachment_definitions[name] = {}
32
+ attachment_definitions[name] = opts
33
33
 
34
34
  key "#{name}_size".to_sym, Integer
35
35
  key "#{name}_path".to_sym, String
@@ -40,7 +40,7 @@ module Grip
40
40
  # open returns the correct mime-type,
41
41
  # read returns a string. Not sure if
42
42
  # this is a GridFS problem or not
43
- GridFS::GridStore.open(self.class.database, self["#{name}_path"], 'r') {|f| f.read }
43
+ GridFS::GridStore.open(self.class.database, self["#{name}_path"], 'r') {|f| f }
44
44
  end
45
45
 
46
46
  define_method("#{name}=") do |file|
@@ -49,7 +49,7 @@ module Grip
49
49
  self["#{name}_name"] = File.basename(file.path)
50
50
  self["#{name}_path"] = "#{self.class.to_s.underscore}/#{name}/#{_id}"
51
51
  self["#{name}_content_type"] = file.content_type rescue MIME::Types.type_for(self["#{name}_name"]).to_s
52
- self.class.attachment_definitions[name] = file
52
+ self.class.attachment_definitions[name][:file] = file
53
53
  end
54
54
  end
55
55
 
@@ -60,16 +60,21 @@ module Grip
60
60
 
61
61
  def save_attachments
62
62
  self.class.attachment_definitions.each do |attachment|
63
- name, file = attachment
64
63
 
65
- if (file.is_a?(File) || file.is_a?(Tempfile))
64
+ name, opts = attachment
65
+
66
+ if (opts[:file].is_a?(File) || opts[:file].is_a?(Tempfile))
66
67
  GridFS::GridStore.open(self.class.database, self["#{name}_path"], 'w', :content_type => self["#{name}_content_type"]) do |f|
67
- f.write(file.read)
68
+ f.write( grip_process_file(opts))
68
69
  end
69
70
  end
70
71
  end
71
72
  end
72
73
 
74
+ def grip_process_file opts
75
+ opts[:file]
76
+ end
77
+
73
78
  def destroy_attached_files
74
79
  self.class.attachment_definitions.each do |name, attachment|
75
80
  GridFS::GridStore.unlink(self.class.database, self["#{name}_path"])
data/test/test_grip.rb CHANGED
@@ -4,8 +4,12 @@ class Foo
4
4
  include MongoMapper::Document
5
5
  include Grip
6
6
 
7
- has_grid_attachment :image
7
+ has_grid_attachment :image, :resize => {:width=>50,:height=>50}
8
8
  has_grid_attachment :pdf
9
+
10
+ def grip_process_file opts
11
+ opts[:file]
12
+ end
9
13
  end
10
14
 
11
15
  class GripTest < Test::Unit::TestCase
@@ -59,11 +63,8 @@ class GripTest < Test::Unit::TestCase
59
63
  end
60
64
 
61
65
  test "saves attachments correctly" do
62
- # can't get these to pass locally but the
63
- # files are there and working. WTF??
64
-
65
- #assert_equal @image.read, @doc.image
66
- #assert_equal @pdf.read, @doc.pdf
66
+ assert_equal "image/png", @doc.image.content_type
67
+ assert_equal "application/pdf", @doc.pdf.content_type
67
68
 
68
69
  assert GridFS::GridStore.exist?(MongoMapper.database, @doc.image_path)
69
70
  assert GridFS::GridStore.exist?(MongoMapper.database, @doc.pdf_path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - twoism