Class: PostImageManager
- Inherits:
-
Object
- Object
- PostImageManager
- Includes:
- Singleton
- Defined in:
- lib/models/post_image_manager.rb
Overview
A singleton class for managing all image attachments for a post
Instance Attribute Summary collapse
-
#downloaded_images ⇒ Object
readonly
Returns the value of attribute downloaded_images.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#uploaders ⇒ Object
readonly
Returns the value of attribute uploaders.
Instance Method Summary collapse
-
#add_downloaded_image(downloaded_image) ⇒ Object
Adds an image that was downloaded from the Jekyll website repo.
-
#add_file(file) ⇒ Object
Adds an image to be uploaded in a Jekyll website post.
-
#clear ⇒ Object
Clears the manager of all currently exisiting image uploaders and delete’s their cache directories.
-
#initialize ⇒ PostImageManager
constructor
The constructor for PostImageManager which initializes the array of Carrierware image uploaders to use when submiting a post and the array of downloaded images.
Constructor Details
#initialize ⇒ PostImageManager
The constructor for PostImageManager which initializes the array of Carrierware image uploaders to use when submiting a post and the array of downloaded images
17 18 19 20 21 |
# File 'lib/models/post_image_manager.rb', line 17 def initialize @uploaders = [] @downloaded_images = [] @root_dir = '' end |
Instance Attribute Details
#downloaded_images ⇒ Object (readonly)
Returns the value of attribute downloaded_images.
11 12 13 |
# File 'lib/models/post_image_manager.rb', line 11 def downloaded_images @downloaded_images end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
12 13 14 |
# File 'lib/models/post_image_manager.rb', line 12 def root_dir @root_dir end |
#uploaders ⇒ Object (readonly)
Returns the value of attribute uploaders.
10 11 12 |
# File 'lib/models/post_image_manager.rb', line 10 def uploaders @uploaders end |
Instance Method Details
#add_downloaded_image(downloaded_image) ⇒ Object
Adds an image that was downloaded from the Jekyll website repo
Params:
downloaded_image-
A PostImage object representing the downloaded image
40 41 42 |
# File 'lib/models/post_image_manager.rb', line 40 def add_downloaded_image(downloaded_image) @downloaded_images << downloaded_image end |
#add_file(file) ⇒ Object
Adds an image to be uploaded in a Jekyll website post
Params:
file-
A ActionDispatch::Http::UploadedFile object containing the file to be used in a post
28 29 30 31 32 33 |
# File 'lib/models/post_image_manager.rb', line 28 def add_file(file) uploader_to_add = PostImageUploader.new uploader_to_add.cache!(file) @uploaders.delete_if { |x| x.filename == file.original_filename } @uploaders << uploader_to_add end |
#clear ⇒ Object
Clears the manager of all currently exisiting image uploaders and delete’s their cache directories. Also clears the manager of all of the downloaded images
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/models/post_image_manager.rb', line 47 def clear @uploaders.each do |uploader| full_preview_path = "#{@root_dir}/public/uploads/tmp/#{uploader.preview.cache_name}" cache_dir = File.('..', full_preview_path) uploader.remove! Dir.delete(cache_dir) end @uploaders.clear @downloaded_images.clear end |