Class: VenusMediaLibrary::Configuration
- Inherits:
-
Object
- Object
- VenusMediaLibrary::Configuration
- Defined in:
- lib/venus_media_library.rb
Overview
Host apps configure the engine through VenusMediaLibrary.configure:
VenusMediaLibrary.configure do |config|
config.allowed_content_types = %w[image/png image/jpeg image/webp]
config.thumbnail_size = [ 300, 300 ]
config.per_page = 40
config.storage_service = :amazon
end
Instance Attribute Summary collapse
-
#allowed_content_types ⇒ Object
Content types accepted by the uploader and shown in the library grid.
-
#authenticate_with ⇒ Object
Optional access gate.
-
#per_page ⇒ Object
Number of images per page in the index.
-
#storage_service ⇒ Object
Optional Active Storage service name to attach uploads to.
-
#thumbnail_size ⇒ Object
[width, height] used for the grid thumbnail variant.
-
#url_type ⇒ Object
How image URLs in the payload/picker are built: :redirect (default) -> rails_blob_url (302s to the storage URL) :proxy -> rails_storage_proxy_url (Rails streams the bytes) Use :proxy when the bucket is private and images must be publicly fetchable by external crawlers (e.g. an og:image on a private S3 bucket in proxy mode).
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 |
# File 'lib/venus_media_library.rb', line 48 def initialize @allowed_content_types = %w[image/png image/jpeg image/jpg image/gif image/webp image/svg+xml] @thumbnail_size = [ 300, 300 ] @per_page = 40 @storage_service = nil @url_type = :redirect @authenticate_with = nil end |
Instance Attribute Details
#allowed_content_types ⇒ Object
Content types accepted by the uploader and shown in the library grid. Every entry is matched literally; the index additionally shows any blob whose content_type starts with "image/".
17 18 19 |
# File 'lib/venus_media_library.rb', line 17 def allowed_content_types @allowed_content_types end |
#authenticate_with ⇒ Object
Optional access gate. A proc run in the engine controller's context before
every action (via instance_exec), so it can call host helpers like
current_user, redirect_to, or head. Left nil the engine is open; the
host sets this to restrict the picker/upload endpoints to admins.
VenusMediaLibrary.configure do |c|
c.authenticate_with = -> { redirect_to main_app.root_path unless current_user&.admin? }
end
46 47 48 |
# File 'lib/venus_media_library.rb', line 46 def authenticate_with @authenticate_with end |
#per_page ⇒ Object
Number of images per page in the index.
23 24 25 |
# File 'lib/venus_media_library.rb', line 23 def per_page @per_page end |
#storage_service ⇒ Object
Optional Active Storage service name to attach uploads to. When nil the
host app's default service (config.active_storage.service) is used, so
the engine stays storage-agnostic (Disk in dev, S3 in prod, etc.).
28 29 30 |
# File 'lib/venus_media_library.rb', line 28 def storage_service @storage_service end |
#thumbnail_size ⇒ Object
[width, height] used for the grid thumbnail variant.
20 21 22 |
# File 'lib/venus_media_library.rb', line 20 def thumbnail_size @thumbnail_size end |
#url_type ⇒ Object
How image URLs in the payload/picker are built:
:redirect (default) -> rails_blob_url (302s to the storage URL)
:proxy -> rails_storage_proxy_url (Rails streams the bytes)
Use :proxy when the bucket is private and images must be publicly fetchable by external crawlers (e.g. an og:image on a private S3 bucket in proxy mode). Still storage-agnostic: both are Active Storage route helpers.
36 37 38 |
# File 'lib/venus_media_library.rb', line 36 def url_type @url_type end |