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
19 20 21 22 23 |
# File 'lib/models/post_image_manager.rb', line 19 def initialize @uploaders = [] @downloaded_images = [] @root_dir = '' end |
Instance Attribute Details
#downloaded_images ⇒ Object (readonly)
Returns the value of attribute downloaded_images.
13 14 15 |
# File 'lib/models/post_image_manager.rb', line 13 def downloaded_images @downloaded_images end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
14 15 16 |
# File 'lib/models/post_image_manager.rb', line 14 def root_dir @root_dir end |
#uploaders ⇒ Object (readonly)
Returns the value of attribute uploaders.
12 13 14 |
# File 'lib/models/post_image_manager.rb', line 12 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
42 43 44 |
# File 'lib/models/post_image_manager.rb', line 42 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
30 31 32 33 34 35 |
# File 'lib/models/post_image_manager.rb', line 30 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
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/models/post_image_manager.rb', line 49 def clear # @uploaders.each do |uploader| # full_preview_path = "#{@root_dir}/public/uploads/tmp/#{uploader.preview.cache_name}" # cache_dir = File.expand_path('..', full_preview_path) # uploader.remove! # Dir.delete(cache_dir) # end # @uploaders.clear # @downloaded_images.clear end |