Module: Attacheable::ClassMethods
- Defined in:
- lib/attacheable.rb
Instance Method Summary collapse
-
#autosave_to_development(production_host) ⇒ Object
If you regularly dump Your database from production to development, You will get problems with downloading assets.
-
#data_by_path_info(path_info) ⇒ Object
It is designed to read params, or splitted PATH_INFO in mongrel handler It assumes, that path_info is of the following format [“0000”, “0001”, “file_medium.jpg”].
- #image_height(filename) ⇒ Object
- #image_width(filename) ⇒ Object
-
#regenerate_thumbnails!(thumbnail = nil) ⇒ Object
You can delete all thumbnails or with selected type.
Instance Method Details
#autosave_to_development(production_host) ⇒ Object
If you regularly dump Your database from production to development, You will get problems with downloading assets. It is a real problem to download 8Gb of unused pictures. Download only those photos, which you need.
autosave_to_development("prophotos.ru") if RAILS_ENV == "development"
Warning!! It will very slow.
101 102 103 104 |
# File 'lib/attacheable.rb', line 101 def autosave_to_development(production_host) [:production_host] = production_host alias_method_chain :public_filename, :download end |
#data_by_path_info(path_info) ⇒ Object
It is designed to read params, or splitted PATH_INFO in mongrel handler It assumes, that path_info is of the following format [“0000”, “0001”, “file_medium.jpg”]
119 120 121 122 123 124 125 126 127 |
# File 'lib/attacheable.rb', line 119 def data_by_path_info(path_info) id1, id2, path = path_info return [nil, nil] unless id1 && id2 && path object = find(id1.to_i*1000 + id2.to_i) if path = object.full_filename_by_path(path) return [object, File.read(path)] if File.exists?(path) end [object, nil] end |
#image_height(filename) ⇒ Object
133 134 135 |
# File 'lib/attacheable.rb', line 133 def image_height(filename) `identify -format "%h" "#{filename}"`.to_i end |
#image_width(filename) ⇒ Object
129 130 131 |
# File 'lib/attacheable.rb', line 129 def image_width(filename) `identify -format "%w" "#{filename}"`.to_i end |
#regenerate_thumbnails!(thumbnail = nil) ⇒ Object
You can delete all thumbnails or with selected type
109 110 111 112 113 114 |
# File 'lib/attacheable.rb', line 109 def regenerate_thumbnails!(thumbnail = nil) connection.select_values(send(:construct_finder_sql, :select => "id")).each do |object_id| object = find_by_id(object_id) object.destroy_thumbnails!(thumbnail) end end |