public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
full_filename, you're banished from the land
rick (author)
Wed Apr 30 16:30:49 -0700 2008
commit  d2a3164676876fb0598c8e0203610e056d45ac51
tree    3fcabaa2d0dbeec2e31efbcfab99c36ec5d5a14e
parent  f73671e84b90fb0e4fd52d2f035684d1c02828a8
...
150
151
152
153
154
155
156
157
158
 
159
160
161
162
163
 
164
165
166
...
264
265
266
267
268
 
 
269
270
271
...
283
284
285
286
287
288
 
 
 
289
290
 
291
292
293
...
150
151
152
 
 
 
 
 
153
154
155
156
157
158
159
160
161
162
163
...
261
262
263
 
 
264
265
266
267
268
...
280
281
282
 
 
 
283
284
285
286
 
287
288
289
290
0
@@ -150,17 +150,14 @@ module AttachmentFu
0
       ("%08d" % attachment_path_id).scan(/..../) + args
0
     end
0
 
0
- # Returns the full path for an attachment
0
- def full_filename
0
- full_path(filename)
0
- end
0
-
0
     def public_path(*args)
0
+ args = [filename] if args.empty?
0
       File.join(attachment_path, *partitioned_path(*args)).sub(/^public\//, '/')
0
     end
0
 
0
     def full_path(*args)
0
       return nil if attachment_path_id.nil?
0
+ args = [filename] if args.empty?
0
       File.expand_path(File.join(AttachmentFu.root_path, attachment_path, *partitioned_path(*args)))
0
     end
0
 
0
@@ -264,8 +261,8 @@ module AttachmentFu
0
     # Deletes the attachment from tbhe file system, and attempts
0
     # to clean up the empty asset paths.
0
     def delete_attachment
0
- FileUtils.rm full_filename if File.exist?(full_filename)
0
- dir_name = File.dirname(full_filename)
0
+ FileUtils.rm full_path if File.exist?(full_path)
0
+ dir_name = File.dirname(full_path)
0
       default = %w(. ..)
0
       while dir_name != AttachmentFu.root_path
0
         if (Dir.entries(dir_name) - default).empty?
0
@@ -283,11 +280,11 @@ module AttachmentFu
0
       return if @temp_path.nil?
0
       old_path = File.expand_path(full_path_for(@temp_path))
0
       return if old_path.nil?
0
- unless old_path == full_filename
0
- FileUtils.mkdir_p(File.dirname(full_filename))
0
- FileUtils.mv(old_path, full_filename)
0
+ unless old_path == full_path
0
+ FileUtils.mkdir_p(File.dirname(full_path))
0
+ FileUtils.mv(old_path, full_path)
0
       end
0
- File.chmod(0644, full_filename)
0
+ File.chmod(0644, full_path)
0
       @temp_path = nil # if a task tries to re-save, we don't want to re-store the attachment
0
       queued_attachment ? queue_processing : process
0
       @new_attachment = nil
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ module AttachmentFu # :nodoc:
0
   module Pixels
0
     module CoreImage
0
       def with_image(attachment, &block)
0
- block.call OSX::CIImage.from(attachment.full_filename)
0
+ block.call OSX::CIImage.from(attachment.full_path)
0
       end
0
 
0
       def get_image_size(image)
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ module AttachmentFu # :nodoc:
0
   module Pixels
0
     module MojoMagick
0
       def with_image(attachment, &block)
0
- block.call attachment.full_filename
0
+ block.call attachment.full_path
0
       end
0
 
0
       def get_image_size(image)
...
15
16
17
18
19
 
 
20
21
22
...
56
57
58
59
 
60
61
62
63
 
64
65
66
67
68
 
69
70
71
...
75
76
77
78
 
79
80
81
...
93
94
95
96
 
97
98
99
...
102
103
104
105
 
106
107
108
...
15
16
17
 
 
18
19
20
21
22
...
56
57
58
 
59
60
61
62
 
63
64
65
66
67
 
68
69
70
71
...
75
76
77
 
78
79
80
81
...
93
94
95
 
96
97
98
99
...
102
103
104
 
105
106
107
108
0
@@ -15,8 +15,8 @@ module AttachmentFu
0
         @asset = BasicAsset.new(:content_type => 'application/x-ruby', :temp_path => __FILE__)
0
       end
0
 
0
- it "has nil #full_filename" do
0
- @asset.full_filename.should be_nil
0
+ it "has nil #full_path" do
0
+ @asset.full_path.should be_nil
0
       end
0
 
0
       it "has nil #partitioned_path" do
0
@@ -56,16 +56,16 @@ module AttachmentFu
0
       end
0
 
0
       it "stores asset in AttachmentFu root_path" do
0
- @asset.full_filename.should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig.rb"))
0
+ @asset.full_path.should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig.rb"))
0
       end
0
 
0
       it "creates full_path from record id and attachment_path" do
0
- @asset.full_path.should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}"))
0
+ @asset.full_path.should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/#{@asset.filename}"))
0
         @asset.full_path("foo", "bar").should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/foo/bar"))
0
       end
0
 
0
       it "creates public_path from record id and attachment_path" do
0
- @asset.public_path.should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}"
0
+ @asset.public_path.should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/#{@asset.filename}"
0
         @asset.public_path("foo", "bar").should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/foo/bar"
0
       end
0
 
0
@@ -75,7 +75,7 @@ module AttachmentFu
0
       end
0
 
0
       it "moves temp_path to new location" do
0
- File.exist?(@asset.full_filename).should == true
0
+ File.exist?(@asset.full_path).should == true
0
       end
0
 
0
       it "removes old temp_path location" do
0
@@ -93,7 +93,7 @@ module AttachmentFu
0
         FileUtils.cp __FILE__, @file
0
 
0
         @asset = BasicAsset.create!(:content_type => 'application/x-ruby', :temp_path => @file)
0
- @dir = File.dirname(@asset.full_filename)
0
+ @dir = File.dirname(@asset.full_path)
0
       end
0
       
0
       after do
0
@@ -102,7 +102,7 @@ module AttachmentFu
0
       
0
       it "removes the file" do
0
         @asset.destroy
0
- File.exist?(@asset.full_filename).should == false
0
+ File.exist?(@asset.full_path).should == false
0
       end
0
       
0
       (1..4).each do |i|
...
14
15
16
17
 
18
19
20
...
14
15
16
 
17
18
19
20
0
@@ -14,7 +14,7 @@ describe AttachmentFu::Pixels::CoreImage do
0
   describe "(for JPG)" do
0
     before do
0
       @attachment = mock("Attachment")
0
- @attachment.stub!(:full_filename).and_return(File.join(@samples, 'casshern.jpg'))
0
+ @attachment.stub!(:full_path).and_return(File.join(@samples, 'casshern.jpg'))
0
     end
0
 
0
     it "gets accurate dimensions" do
...
14
15
16
17
 
18
19
20
...
14
15
16
 
17
18
19
20
0
@@ -14,7 +14,7 @@ describe AttachmentFu::Pixels::MojoMagick do
0
   describe "(for JPG)" do
0
     before do
0
       @attachment = mock("Attachment")
0
- @attachment.stub!(:full_filename).and_return(File.join(@samples, 'casshern.jpg'))
0
+ @attachment.stub!(:full_path).and_return(File.join(@samples, 'casshern.jpg'))
0
     end
0
 
0
     it "gets accurate dimensions" do
...
20
21
22
23
 
24
25
26
...
20
21
22
 
23
24
25
26
0
@@ -20,7 +20,7 @@ module AttachmentFu
0
     end
0
     
0
     it "saves attachment" do
0
- File.exist? @asset.full_filename
0
+ File.exist? @asset.full_path
0
     end
0
     
0
     it "resizes image" do
...
20
21
22
23
 
24
25
26
...
20
21
22
 
23
24
25
26
0
@@ -20,7 +20,7 @@ module AttachmentFu
0
     end
0
 
0
     it "saves attachment" do
0
- File.exist? @asset.full_filename
0
+ File.exist? @asset.full_path
0
     end
0
 
0
     it "creates correct number of thumbnails with matching thumbnail keys" do

Comments

    No one has commented yet.