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
-
#admin ⇒ Object
The current signed-in host user and the role predicate.
-
#allowed_content_types ⇒ Object
Content types accepted by the uploader.
-
#authenticate_with ⇒ Object
Optional access gate.
-
#current_user ⇒ Object
The current signed-in host user and the role predicate.
-
#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
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.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/venus_media_library.rb', line 46 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 @current_user = -> { current_user } @admin = ->(user) { user.admin? } 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.
44 45 46 |
# File 'lib/venus_media_library.rb', line 44 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 |
#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
40 41 42 |
# File 'lib/venus_media_library.rb', line 40 def authenticate_with @authenticate_with 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.
44 45 46 |
# File 'lib/venus_media_library.rb', line 44 def current_user @current_user end |
#per_page ⇒ Object
Number of images per page in the index.
21 22 23 |
# File 'lib/venus_media_library.rb', line 21 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.).
26 27 28 |
# File 'lib/venus_media_library.rb', line 26 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.
30 31 32 |
# File 'lib/venus_media_library.rb', line 30 def url_type @url_type end |