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
Constant Summary collapse
- DEFAULT_ADMIN =
Default admin predicate. A gem shouldn't break just because a host app names its flag differently, so try the two common conventions —
admin?thenis_admin?— and fall back to non-admin. Hosts with any other scheme set their ownconfig.admin = ->(user) { ... }. lambda do |user| return false if user.nil? return !!user.admin? if user.respond_to?(:admin?) return !!user.is_admin? if user.respond_to?(:is_admin?) false end
Instance Attribute Summary collapse
-
#admin ⇒ Object
The current signed-in host user and the role predicate.
-
#allowed_content_types ⇒ Object
Content types accepted by the uploader.
-
#asset_scope ⇒ Object
Controller-context callbacks that narrow the engine's records for a host tenant.
-
#authenticate_with ⇒ Object
Optional access gate.
-
#cloud_assets ⇒ Object
Controller-context callback returning approved cloud asset hashes supplied by the host.
-
#current_user ⇒ Object
The current signed-in host user and the role predicate.
-
#legacy_blob_scope ⇒ Object
Controller-context callbacks that narrow the engine's records for a host tenant.
-
#max_file_size ⇒ Object
Maximum accepted upload size in bytes.
-
#per_page ⇒ Object
Number of media assets per page in the index.
-
#static_assets ⇒ Object
Controller-context callback returning static asset hashes supplied by the host.
-
#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
Retained for compatibility with older host configuration.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/venus_media_library.rb', line 77 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 @max_file_size = 10 * 1024 * 1024 @storage_service = nil @url_type = :redirect @authenticate_with = nil @current_user = -> { current_user } @admin = DEFAULT_ADMIN @asset_scope = ->(scope) { scope } @legacy_blob_scope = ->(scope) { scope.none } @static_assets = -> { [] } @cloud_assets = -> { [] } end |
Instance Attribute Details
#admin ⇒ Object
The current signed-in host user and the role predicate. Both callbacks run
in the engine controller context. By default this uses the host's
current_user and current_user.admin? convention.
47 48 49 |
# File 'lib/venus_media_library.rb', line 47 def admin @admin end |
#allowed_content_types ⇒ Object
Content types accepted by the uploader. Every entry is matched literally.
15 16 17 |
# File 'lib/venus_media_library.rb', line 15 def allowed_content_types @allowed_content_types end |
#asset_scope ⇒ Object
Controller-context callbacks that narrow the engine's records for a host tenant. Each receives an Active Record relation and must return a relation. Legacy blobs default to none because they have no owner and may belong to another tenant.
53 54 55 |
# File 'lib/venus_media_library.rb', line 53 def asset_scope @asset_scope 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
43 44 45 |
# File 'lib/venus_media_library.rb', line 43 def authenticate_with @authenticate_with end |
#cloud_assets ⇒ Object
Controller-context callback returning approved cloud asset hashes supplied
by the host. This has the same shape as static_assets and intentionally
does not enumerate a cloud bucket or expose storage-provider credentials.
63 64 65 |
# File 'lib/venus_media_library.rb', line 63 def cloud_assets @cloud_assets end |
#current_user ⇒ Object
The current signed-in host user and the role predicate. Both callbacks run
in the engine controller context. By default this uses the host's
current_user and current_user.admin? convention.
47 48 49 |
# File 'lib/venus_media_library.rb', line 47 def current_user @current_user end |
#legacy_blob_scope ⇒ Object
Controller-context callbacks that narrow the engine's records for a host tenant. Each receives an Active Record relation and must return a relation. Legacy blobs default to none because they have no owner and may belong to another tenant.
53 54 55 |
# File 'lib/venus_media_library.rb', line 53 def legacy_blob_scope @legacy_blob_scope end |
#max_file_size ⇒ Object
Maximum accepted upload size in bytes.
24 25 26 |
# File 'lib/venus_media_library.rb', line 24 def max_file_size @max_file_size end |
#per_page ⇒ Object
Number of media assets per page in the index.
21 22 23 |
# File 'lib/venus_media_library.rb', line 21 def per_page @per_page end |
#static_assets ⇒ Object
Controller-context callback returning static asset hashes supplied by the host. Each hash should include :filename and :url, with optional :content_type and :byte_size. The engine never scans host directories.
58 59 60 |
# File 'lib/venus_media_library.rb', line 58 def static_assets @static_assets 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.).
29 30 31 |
# File 'lib/venus_media_library.rb', line 29 def storage_service @storage_service end |
#thumbnail_size ⇒ Object
[width, height] used for the grid thumbnail variant.
18 19 20 |
# File 'lib/venus_media_library.rb', line 18 def thumbnail_size @thumbnail_size end |
#url_type ⇒ Object
Retained for compatibility with older host configuration. Library URLs are always served through authorization-aware engine routes.
33 34 35 |
# File 'lib/venus_media_library.rb', line 33 def url_type @url_type end |