Class: Plutonium::Configuration
- Inherits:
-
Object
- Object
- Plutonium::Configuration
- Defined in:
- lib/plutonium/configuration.rb
Overview
Configuration class for Plutonium module
Defined Under Namespace
Classes: AssetConfiguration
Constant Summary collapse
- NESTED_ASSOCIATION_ROUTE_MODES =
Valid values for #nested_association_routes.
%i[detected declared].freeze
- VERSION_DEFAULTS =
Map of version numbers to their default configurations
{ 1.0 => proc do |config| # No changes for 1.0 yet as it's the current base configuration end # Add more version configurations here as needed # 1.1 => proc do |config| # config.some_new_setting = true # end }.freeze
Instance Attribute Summary collapse
-
#assets ⇒ AssetConfiguration
readonly
Asset configuration.
-
#async_interactions ⇒ Plutonium::Interaction::Async::Configuration
readonly
Persisted interaction runs configuration — gates the runs subsystem and its migrations.
- #attachment_backend ⇒ Plutonium::Wizard::Configuration, ...
-
#auto_eager_load_collections ⇒ Boolean
Whether a rendered collection — an index page, a kanban board, a CSV export — eager-loads the associations and attachments it is about to show.
-
#cache_discovery ⇒ Boolean
Whether to cache discovery.
-
#default_currency_unit ⇒ String, ...
The currency unit (symbol) used when rendering a currency value that has no unit configured on
has_centsor the display. -
#default_page_width ⇒ Symbol
The default width for detail-style pages — the show page, resource forms and wizard steps.
-
#default_phone_country ⇒ String?
The default country (ISO2 code, e.g. "gh") for phone (
as: :phone) inputs that don't set their owninitial_country:. -
#defaults_version ⇒ Float
readonly
The current defaults version.
-
#development ⇒ Boolean
Whether Plutonium is in development mode.
-
#enable_hotreload ⇒ Boolean
Whether to enable hot reloading.
-
#navii_host_url ⇒ String
Host URL of the Navii avatar service (no path), used by UI::Avatar as the default profile-image fallback.
-
#nested_association_routes ⇒ Symbol
Where a resource's nested routes come from.
-
#normalized_default_phone_country ⇒ String?
readonly
#default_phone_country downcased to the lowercase ISO2 form intl-tel-input expects, so callers can set "GH" or "gh" interchangeably.
-
#shell ⇒ Symbol
:modern (Topbar/IconRail, default), :plain (Topbar, no icon rail), or :classic (legacy Header/Sidebar).
-
#wizards ⇒ Object
readonly
Returns the value of attribute wizards.
Instance Method Summary collapse
-
#development? ⇒ Boolean
whether Plutonium is in development mode.
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration instance.
-
#load_defaults(version) ⇒ void
Load default configuration for a specific version.
Constructor Details
#initialize ⇒ Configuration
This method sets initial values
Initialize a new Configuration instance
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/plutonium/configuration.rb', line 146 def initialize @defaults_version = nil @assets = AssetConfiguration.new @wizards = Plutonium::Wizard::Configuration.new @async_interactions = Plutonium::Interaction::Async::Configuration.new @development = parse_boolean_env("PLUTONIUM_DEV") @cache_discovery = !Rails.env.development? @enable_hotreload = Rails.env.development? @shell = :modern @navii_host_url = "https://api.navii.dev" @auto_eager_load_collections = true @default_page_width = :md @nested_association_routes = :detected end |
Instance Attribute Details
#assets ⇒ AssetConfiguration (readonly)
Returns asset configuration.
25 26 27 |
# File 'lib/plutonium/configuration.rb', line 25 def assets @assets end |
#async_interactions ⇒ Plutonium::Interaction::Async::Configuration (readonly)
Returns persisted interaction runs configuration — gates the runs subsystem and its migrations.
41 42 43 |
# File 'lib/plutonium/configuration.rb', line 41 def async_interactions @async_interactions end |
#attachment_backend ⇒ Plutonium::Wizard::Configuration, ...
35 36 37 |
# File 'lib/plutonium/configuration.rb', line 35 def @attachment_backend end |
#auto_eager_load_collections ⇒ Boolean
Returns whether a rendered collection — an index page, a kanban board, a CSV export — eager-loads the associations and attachments it is about to show. On by default.
The rendered field set is declared, not discovered: it is resolved from
the policy before the collection loads, so the framework already knows
which associations will be touched and can preload exactly those. Turn it
off globally here, or per controller via auto_eager_load_collections?.
80 81 82 |
# File 'lib/plutonium/configuration.rb', line 80 def auto_eager_load_collections @auto_eager_load_collections end |
#cache_discovery ⇒ Boolean
Returns whether to cache discovery.
19 20 21 |
# File 'lib/plutonium/configuration.rb', line 19 def cache_discovery @cache_discovery end |
#default_currency_unit ⇒ String, ...
Returns the currency unit (symbol) used when rendering
a currency value that has no unit configured on has_cents or the display.
nil (default) falls back to the i18n number.currency.format.unit when
the locale defines it, otherwise no symbol. Set a literal like "£" to
change the default, or false (or "") for no symbol application-wide.
61 62 63 |
# File 'lib/plutonium/configuration.rb', line 61 def default_currency_unit @default_currency_unit end |
#default_page_width ⇒ Symbol
Returns the default width for detail-style pages — the show
page, resource forms and wizard steps. One of
UI::PageWidth::VALID_SIZES; :full opts out of any
constraint. Definitions override per-resource via page_width
(and form_width / display_width for one surface only).
Index and table pages are NOT affected — they want every pixel.
70 71 72 |
# File 'lib/plutonium/configuration.rb', line 70 def default_page_width @default_page_width end |
#default_phone_country ⇒ String?
Returns the default country (ISO2 code, e.g. "gh") for phone
(as: :phone) inputs that don't set their own initial_country:. nil
(default) leaves it to the intl-tel-input library (no country preselected).
Stored verbatim — read it back exactly as set. Consumers that feed
intl-tel-input should use #normalized_default_phone_country.
87 88 89 |
# File 'lib/plutonium/configuration.rb', line 87 def default_phone_country @default_phone_country end |
#defaults_version ⇒ Float (readonly)
Returns the current defaults version.
44 45 46 |
# File 'lib/plutonium/configuration.rb', line 44 def defaults_version @defaults_version end |
#development ⇒ Boolean
Returns whether Plutonium is in development mode.
16 17 18 |
# File 'lib/plutonium/configuration.rb', line 16 def development @development end |
#enable_hotreload ⇒ Boolean
Returns whether to enable hot reloading.
22 23 24 |
# File 'lib/plutonium/configuration.rb', line 22 def enable_hotreload @enable_hotreload end |
#navii_host_url ⇒ String
Returns host URL of the Navii avatar service (no path), used by
UI::Avatar as the default profile-image fallback. The
component appends the /avatar/:seed route. Repoint this to self-host
or proxy the service.
54 55 56 |
# File 'lib/plutonium/configuration.rb', line 54 def navii_host_url @navii_host_url end |
#nested_association_routes ⇒ Symbol
Returns where a resource's nested routes come from.
:detected (default) draws one for every has_many and has_one whose
child is a registered resource, which is how Plutonium has always behaved.
:declared draws only what register_resource names:
register_resource ::Post, associations: %i[comments post_detail]
A resource that names none then gets no nested routes at all. Naming associations works in either mode; the mode only decides what silence means.
Note that a policy's permitted_associations renders a panel on the show
page that links to the nested route, so an association permitted there and
omitted here has a panel with nowhere to point.
117 118 119 |
# File 'lib/plutonium/configuration.rb', line 117 def nested_association_routes @nested_association_routes end |
#normalized_default_phone_country ⇒ String? (readonly)
Returns #default_phone_country downcased to the lowercase
ISO2 form intl-tel-input expects, so callers can set "GH" or "gh"
interchangeably. nil stays nil. Computed once on assignment.
92 93 94 |
# File 'lib/plutonium/configuration.rb', line 92 def normalized_default_phone_country @normalized_default_phone_country end |
#shell ⇒ Symbol
Returns :modern (Topbar/IconRail, default), :plain (Topbar, no icon rail), or :classic (legacy Header/Sidebar).
48 49 50 |
# File 'lib/plutonium/configuration.rb', line 48 def shell @shell end |
#wizards ⇒ Object (readonly)
Returns the value of attribute wizards.
37 38 39 |
# File 'lib/plutonium/configuration.rb', line 37 def wizards @wizards end |
Instance Method Details
#development? ⇒ Boolean
whether Plutonium is in development mode
184 185 186 |
# File 'lib/plutonium/configuration.rb', line 184 def development? @development end |
#load_defaults(version) ⇒ void
This method returns an undefined value.
Load default configuration for a specific version
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/plutonium/configuration.rb', line 166 def load_defaults(version) available_versions = VERSION_DEFAULTS.keys.sort applicable_versions = available_versions.select { |v| v <= version } if applicable_versions.empty? raise "No applicable defaults found for version #{version}." end applicable_versions.each do |v| VERSION_DEFAULTS[v].call(self) end @defaults_version = applicable_versions.last end |