grip 0.6.0 → 0.6.1
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 +1 -1
- data/VERSION +1 -1
- data/grip.gemspec +1 -1
- data/lib/grip/attachment.rb +5 -6
- data/lib/grip/has_attachment.rb +1 -2
- data/test/test_has_attachment.rb +0 -4
- metadata +1 -1
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/grip.gemspec
CHANGED
data/lib/grip/attachment.rb
CHANGED
@@ -16,6 +16,7 @@ module MongoMapper
|
|
16
16
|
key :variants, Hash
|
17
17
|
|
18
18
|
after_save :build_variants
|
19
|
+
before_destroy :destroy_file
|
19
20
|
|
20
21
|
def file=new_file
|
21
22
|
raise InvalidFile unless (new_file.is_a?(File) || new_file.is_a?(Tempfile))
|
@@ -35,12 +36,6 @@ module MongoMapper
|
|
35
36
|
"#{owner_type.pluralize}/#{owner_id}/#{name}".downcase
|
36
37
|
end
|
37
38
|
|
38
|
-
def self.create_method sym, &block
|
39
|
-
define_method sym do |*block.args|
|
40
|
-
yield
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
39
|
private
|
45
40
|
def build_variants
|
46
41
|
self.variants.each do |variant, dimensions|
|
@@ -69,6 +64,10 @@ module MongoMapper
|
|
69
64
|
|
70
65
|
end
|
71
66
|
end
|
67
|
+
|
68
|
+
def destroy_file
|
69
|
+
GridFS::GridStore.unlink(self.class.database, grid_key)
|
70
|
+
end
|
72
71
|
|
73
72
|
def write_to_grid new_file
|
74
73
|
GridFS::GridStore.open(self.class.database, grid_key, 'w', :content_type => content_type) do |f|
|
data/lib/grip/has_attachment.rb
CHANGED
@@ -30,8 +30,7 @@ module MongoMapper
|
|
30
30
|
def self.included(base)
|
31
31
|
base.extend ClassMethods
|
32
32
|
base.class_eval do
|
33
|
-
after_save
|
34
|
-
before_destroy :destroy_attached_files
|
33
|
+
after_save :save_attachments
|
35
34
|
|
36
35
|
many :attachments, :as => :owner, :class_name => "MongoMapper::Grip::Attachment", :dependent => :destroy
|
37
36
|
end
|
data/test/test_has_attachment.rb
CHANGED
@@ -26,10 +26,6 @@ class HasAttachmentTest < Test::Unit::TestCase
|
|
26
26
|
assert_equal(1, Doc.after_save.collect(&:method).count)
|
27
27
|
end
|
28
28
|
|
29
|
-
should "have :before_destroy callback" do
|
30
|
-
assert_equal(1, Doc.before_destroy.collect(&:method).count)
|
31
|
-
end
|
32
|
-
|
33
29
|
context "when assigned a file" do
|
34
30
|
setup do
|
35
31
|
@document.image = @image
|