Module: AttachmerbFu::Backends::FileSystemBackend
- Defined in:
- lib/attachmerb_fu/backends/file_system_backend.rb
Overview
Methods for file system backed attachments
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#attachment_path_id ⇒ Object
The attachment ID used in the full path of a file.
-
#base_path ⇒ Object
Used as the base path that #public_filename strips off full_filename to create the public path.
-
#create_temp_file ⇒ Object
Creates a temp file from the currently saved file.
- #filename=(value) ⇒ Object
-
#full_filename(thumbnail = nil) ⇒ Object
Gets the full path to the filename in this format:.
-
#partitioned_path(*args) ⇒ Object
overrwrite this to do your own app-specific partitioning.
-
#public_filename(thumbnail = nil) ⇒ Object
Gets the public path to the file The optional thumbnail argument will output the thumbnail’s filename.
Class Method Details
.included(base) ⇒ Object
:nodoc:
6 7 8 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 6 def self.included(base) #:nodoc: base.before_update :rename_file end |
Instance Method Details
#attachment_path_id ⇒ Object
The attachment ID used in the full path of a file
29 30 31 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 29 def ((respond_to?(:parent_id) && parent_id) || id).to_i end |
#base_path ⇒ Object
Used as the base path that #public_filename strips off full_filename to create the public path
24 25 26 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 24 def base_path @base_path ||= File.join(Merb.root, 'public') end |
#create_temp_file ⇒ Object
Creates a temp file from the currently saved file.
51 52 53 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 51 def create_temp_file copy_to_temp_file full_filename end |
#filename=(value) ⇒ Object
45 46 47 48 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 45 def filename=(value) @old_filename = full_filename unless filename.nil? || @old_filename write_attribute :filename, sanitize_filename(value) end |
#full_filename(thumbnail = nil) ⇒ Object
Gets the full path to the filename in this format:
# This assumes a model name like MyModel
# public/#{table_name} is the default filesystem path
Merb.root/public/my_models/5/blah.jpg
Overwrite this method in your model to customize the filename. The optional thumbnail argument will output the thumbnail’s filename.
18 19 20 21 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 18 def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).[:path_prefix].to_s File.join(Merb.root, file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))) end |
#partitioned_path(*args) ⇒ Object
overrwrite this to do your own app-specific partitioning. you can thank Jamis Buck for this: www.37signals.com/svn/archives2/id_partitioning.php
35 36 37 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 35 def partitioned_path(*args) ("%08d" % ).scan(/..../) + args end |
#public_filename(thumbnail = nil) ⇒ Object
Gets the public path to the file The optional thumbnail argument will output the thumbnail’s filename.
41 42 43 |
# File 'lib/attachmerb_fu/backends/file_system_backend.rb', line 41 def public_filename(thumbnail = nil) full_filename(thumbnail).gsub %r(^#{Regexp.escape(base_path)}), '' end |