Module: Cms::Attachments::Serving

Included in:
Cms::AttachmentsController, ContentController
Defined in:
lib/cms/attachments/attachment_serving.rb

Overview

Can be added to Controllers to handle serving files.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.send_attachments_with#send_attachments

Returns The strategy that will be used to serve files.

Returns:

  • (#send_attachments)

    The strategy that will be used to serve files.



27
28
29
30
# File 'lib/cms/attachments/attachment_serving.rb', line 27

def self.send_attachments_with
  storage = Rails.configuration.cms.attachments.storage
  "Cms::Attachments::#{storage.to_s.classify}Strategy".constantize
end

Instance Method Details

#send_attachment(attachment) ⇒ Object

Send the file if:

1. It exists:
2. The user has permissions to see it.

The strategy used to send the file can be configured based on the config.cms.attachments.storage parameter. Default is:

storage = :filesystem -> Cms::Attachments::FilesystemStrategy


14
15
16
17
18
19
20
# File 'lib/cms/attachments/attachment_serving.rb', line 14

def send_attachment(attachment)
  if attachment
    raise Cms::Errors::AccessDenied unless current_user.able_to_view?(attachment)
    strategy_class = send_attachments_with
    strategy_class.send_attachment(attachment, self)
  end
end

#send_attachments_withObject



22
23
24
# File 'lib/cms/attachments/attachment_serving.rb', line 22

def send_attachments_with
  Cms::Attachments::Serving.send_attachments_with
end