Class: RubyUIAdmin::Configuration
- Inherits:
-
Object
- Object
- RubyUIAdmin::Configuration
- Defined in:
- lib/ruby_ui_admin/configuration.rb
Overview
Central configuration object, configured through RubyUIAdmin.configure.
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Branding / app.
- #authenticate_with(&block) ⇒ Object
-
#authorization_client ⇒ Object
Authorization.
-
#cancancan_ability_class ⇒ Object
Ability class for the CanCanCan adapter (
authorization_client = :cancancan). -
#click_row_to_view_record ⇒ Object
When true, clicking an index row navigates to the record's show page (needs JS).
-
#current_user_method(&block) ⇒ Object
Resolve the current user from the host app context (usually a controller).
-
#docs_enabled ⇒ Object
Controls the in-app docs browser mounted at
<mount>/docs(renders the gem'sdocs/*.md). -
#explicit_authorization ⇒ Object
Returns the value of attribute explicit_authorization.
-
#head_assets ⇒ Object
Head assets (stylesheet + JS tags) for the admin layout.
-
#home_path ⇒ Object
Returns the value of attribute home_path.
-
#javascript ⇒ Object
When true (default), the layout loads the bundled JS (tabs, dialogs).
-
#lazy_tabs ⇒ Object
When true, non-active tabs on the show view load their content lazily (fetched via JS when the tab is first opened, with a spinner) instead of all rendering up front.
-
#locale ⇒ Object
Returns the value of attribute locale.
- #main_menu(&block) ⇒ Object
-
#model_resource_mapping ⇒ Object
Returns the value of attribute model_resource_mapping.
-
#pagination ⇒ Object
Resolved pagination options (calls the proc form if given).
-
#per_page ⇒ Object
Pagination.
-
#per_page_steps ⇒ Object
Returns the value of attribute per_page_steps.
- #profile_menu(&block) ⇒ Object
-
#raise_error_on_missing_policy ⇒ Object
Returns the value of attribute raise_error_on_missing_policy.
-
#resources ⇒ Object
Resource discovery.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
-
#sign_out_method ⇒ Object
HTTP method used by the sign-out item (Devise uses :delete).
-
#sign_out_path_name ⇒ Object
Name of a host route helper (resolved via
main_app) for signing out. -
#timezone ⇒ Object
Returns the value of attribute timezone.
Instance Method Summary collapse
- #authorization_enabled? ⇒ Boolean
-
#countless_pagination? ⇒ Boolean
Whether pagination should run without a COUNT query globally.
-
#docs_enabled? ⇒ Boolean
Whether the in-app docs browser is available in the current environment.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#true_user_method(&block) ⇒ Object
Resolve the real (non-impersonated) user.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ruby_ui_admin/configuration.rb', line 77 def initialize @app_name = "RubyUI Admin" @root_path = "/admin" @home_path = nil @timezone = "UTC" @locale = nil @per_page = 24 @per_page_steps = [12, 24, 48, 72] @current_user_method = nil @true_user_method = nil @authenticate_with = nil @sign_out_path_name = nil @sign_out_method = :delete @authorization_client = :action_policy @explicit_authorization = false @raise_error_on_missing_policy = false @cancancan_ability_class = nil @resources = nil @model_resource_mapping = {} @main_menu = nil @profile_menu = nil @javascript = true @head_assets = nil @click_row_to_view_record = false @lazy_tabs = false @docs_enabled = :local @pagination = {} end |
Instance Attribute Details
#app_name ⇒ Object
Branding / app
7 8 9 |
# File 'lib/ruby_ui_admin/configuration.rb', line 7 def app_name @app_name end |
#authenticate_with(&block) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/ruby_ui_admin/configuration.rb', line 140 def authenticate_with(&block) if block_given? @authenticate_with = block else @authenticate_with end end |
#authorization_client ⇒ Object
Authorization
27 28 29 |
# File 'lib/ruby_ui_admin/configuration.rb', line 27 def @authorization_client end |
#cancancan_ability_class ⇒ Object
Ability class for the CanCanCan adapter (authorization_client = :cancancan). A class or its
name; defaults to the conventional Ability. Ignored by other adapters.
33 34 35 |
# File 'lib/ruby_ui_admin/configuration.rb', line 33 def cancancan_ability_class @cancancan_ability_class end |
#click_row_to_view_record ⇒ Object
When true, clicking an index row navigates to the record's show page (needs JS).
55 56 57 |
# File 'lib/ruby_ui_admin/configuration.rb', line 55 def click_row_to_view_record @click_row_to_view_record end |
#current_user_method(&block) ⇒ Object
Resolve the current user from the host app context (usually a controller).
123 124 125 126 127 128 129 |
# File 'lib/ruby_ui_admin/configuration.rb', line 123 def current_user_method(&block) if block_given? @current_user_method = block else @current_user_method end end |
#docs_enabled ⇒ Object
Controls the in-app docs browser mounted at <mount>/docs (renders the gem's docs/*.md).
Accepts:
:local (default) — mounted in development/test only
true — mounted in all environments, including production (where it sits behind
the admin authentication gate; locally it stays open)
false — never mounted
a callable — evaluated at boot/route-draw time; truthy enables it
Needs kramdown + kramdown-parser-gfm available in the running environment's bundle.
70 71 72 |
# File 'lib/ruby_ui_admin/configuration.rb', line 70 def docs_enabled @docs_enabled end |
#explicit_authorization ⇒ Object
Returns the value of attribute explicit_authorization.
28 29 30 |
# File 'lib/ruby_ui_admin/configuration.rb', line 28 def @explicit_authorization end |
#head_assets ⇒ Object
Head assets (stylesheet + JS tags) for the admin layout. The admin renders the host's
RubyUI components, so the host owns the CSS (Tailwind build) and JS (bundler/importmap that
registers the RubyUI Stimulus controllers + ours). Set this to a proc that returns the
<head> asset markup; it's evaluated in the Rails view context, so it can call helpers like
stylesheet_link_tag / javascript_importmap_tags. When nil, the layout renders no assets.
52 53 54 |
# File 'lib/ruby_ui_admin/configuration.rb', line 52 def head_assets @head_assets end |
#home_path ⇒ Object
Returns the value of attribute home_path.
9 10 11 |
# File 'lib/ruby_ui_admin/configuration.rb', line 9 def home_path @home_path end |
#javascript ⇒ Object
When true (default), the layout loads the bundled JS (tabs, dialogs). The admin works without it (progressive enhancement); set to false to opt out.
45 46 47 |
# File 'lib/ruby_ui_admin/configuration.rb', line 45 def javascript @javascript end |
#lazy_tabs ⇒ Object
When true, non-active tabs on the show view load their content lazily (fetched via JS when the tab is first opened, with a spinner) instead of all rendering up front. Needs JS; without JS the active tab still renders and the others show a "requires JavaScript" notice.
60 61 62 |
# File 'lib/ruby_ui_admin/configuration.rb', line 60 def lazy_tabs @lazy_tabs end |
#locale ⇒ Object
Returns the value of attribute locale.
11 12 13 |
# File 'lib/ruby_ui_admin/configuration.rb', line 11 def locale @locale end |
#main_menu(&block) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/ruby_ui_admin/configuration.rb', line 148 def (&block) if block_given? @main_menu = block else @main_menu end end |
#model_resource_mapping ⇒ Object
Returns the value of attribute model_resource_mapping.
37 38 39 |
# File 'lib/ruby_ui_admin/configuration.rb', line 37 def model_resource_mapping @model_resource_mapping end |
#pagination ⇒ Object
Resolved pagination options (calls the proc form if given).
113 114 115 |
# File 'lib/ruby_ui_admin/configuration.rb', line 113 def pagination @pagination.respond_to?(:call) ? @pagination.call : (@pagination || {}) end |
#per_page ⇒ Object
Pagination
14 15 16 |
# File 'lib/ruby_ui_admin/configuration.rb', line 14 def per_page @per_page end |
#per_page_steps ⇒ Object
Returns the value of attribute per_page_steps.
15 16 17 |
# File 'lib/ruby_ui_admin/configuration.rb', line 15 def per_page_steps @per_page_steps end |
#profile_menu(&block) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/ruby_ui_admin/configuration.rb', line 156 def (&block) if block_given? @profile_menu = block else @profile_menu end end |
#raise_error_on_missing_policy ⇒ Object
Returns the value of attribute raise_error_on_missing_policy.
29 30 31 |
# File 'lib/ruby_ui_admin/configuration.rb', line 29 def raise_error_on_missing_policy @raise_error_on_missing_policy end |
#resources ⇒ Object
Resource discovery
36 37 38 |
# File 'lib/ruby_ui_admin/configuration.rb', line 36 def resources @resources end |
#root_path ⇒ Object
Returns the value of attribute root_path.
8 9 10 |
# File 'lib/ruby_ui_admin/configuration.rb', line 8 def root_path @root_path end |
#sign_out_method ⇒ Object
HTTP method used by the sign-out item (Devise uses :delete).
24 25 26 |
# File 'lib/ruby_ui_admin/configuration.rb', line 24 def sign_out_method @sign_out_method end |
#sign_out_path_name ⇒ Object
Name of a host route helper (resolved via main_app) for signing out. When set, a
sign-out item renders at the bottom of the sidebar. e.g. :destroy_user_session_path
22 23 24 |
# File 'lib/ruby_ui_admin/configuration.rb', line 22 def sign_out_path_name @sign_out_path_name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
10 11 12 |
# File 'lib/ruby_ui_admin/configuration.rb', line 10 def timezone @timezone end |
Instance Method Details
#authorization_enabled? ⇒ Boolean
164 165 166 |
# File 'lib/ruby_ui_admin/configuration.rb', line 164 def !.nil? end |
#countless_pagination? ⇒ Boolean
Whether pagination should run without a COUNT query globally.
118 119 120 |
# File 'lib/ruby_ui_admin/configuration.rb', line 118 def countless_pagination? pagination[:type].to_s == "countless" end |
#docs_enabled? ⇒ Boolean
Whether the in-app docs browser is available in the current environment.
169 170 171 172 173 174 175 |
# File 'lib/ruby_ui_admin/configuration.rb', line 169 def docs_enabled? case docs_enabled when nil, :local then Rails.env.local? when Proc then !!docs_enabled.call else !!docs_enabled end end |
#true_user_method(&block) ⇒ Object
Resolve the real (non-impersonated) user. Defaults to current_user when unset.
132 133 134 135 136 137 138 |
# File 'lib/ruby_ui_admin/configuration.rb', line 132 def true_user_method(&block) if block_given? @true_user_method = block else @true_user_method end end |