Class: Plutonium::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/configuration.rb

Overview

Configuration class for Plutonium module

Examples:

Plutonium.configure do |config|
  config.load_defaults 1.0
  config.development = true
  config.cache_discovery = false
  config.enable_hotreload = true
  config.assets. = "custom_logo.png"
end

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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Note:

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

#assetsAssetConfiguration (readonly)

Returns asset configuration.

Returns:



25
26
27
# File 'lib/plutonium/configuration.rb', line 25

def assets
  @assets
end

#async_interactionsPlutonium::Interaction::Async::Configuration (readonly)

Returns persisted interaction runs configuration — gates the runs subsystem and its migrations.

Returns:



41
42
43
# File 'lib/plutonium/configuration.rb', line 41

def async_interactions
  @async_interactions
end

#attachment_backendPlutonium::Wizard::Configuration, ...

Returns:

  • (Plutonium::Wizard::Configuration)

    wizard subsystem configuration

  • (Symbol, nil)

    the storage backend used to stage an attachment that travels as a plain string — :active_storage or :shrine. nil auto-detects (active_shrine loaded → :shrine, else :active_storage).

    The shared default. Wizards and async interactions each layer their own override on top, so setting this once covers both, and setting one of theirs narrows it to that subsystem.



35
36
37
# File 'lib/plutonium/configuration.rb', line 35

def attachment_backend
  @attachment_backend
end

#auto_eager_load_collectionsBoolean

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?.

Returns:

  • (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. 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_discoveryBoolean

Returns whether to cache discovery.

Returns:

  • (Boolean)

    whether to cache discovery



19
20
21
# File 'lib/plutonium/configuration.rb', line 19

def cache_discovery
  @cache_discovery
end

#default_currency_unitString, ...

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.

Returns:

  • (String, false, nil)

    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_widthSymbol

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.

Returns:

  • (Symbol)

    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_countryString?

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.

Returns:

  • (String, nil)

    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_versionFloat (readonly)

Returns the current defaults version.

Returns:

  • (Float)

    the current defaults version



44
45
46
# File 'lib/plutonium/configuration.rb', line 44

def defaults_version
  @defaults_version
end

#developmentBoolean

Returns whether Plutonium is in development mode.

Returns:

  • (Boolean)

    whether Plutonium is in development mode



16
17
18
# File 'lib/plutonium/configuration.rb', line 16

def development
  @development
end

#enable_hotreloadBoolean

Returns whether to enable hot reloading.

Returns:

  • (Boolean)

    whether to enable hot reloading



22
23
24
# File 'lib/plutonium/configuration.rb', line 22

def enable_hotreload
  @enable_hotreload
end

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.

Returns:

  • (String)

    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_routesSymbol

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.

Returns:

  • (Symbol)

    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_countryString? (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.

Returns:

  • (String, nil)

    #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

#shellSymbol

Returns :modern (Topbar/IconRail, default), :plain (Topbar, no icon rail), or :classic (legacy Header/Sidebar).

Returns:

  • (Symbol)

    :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

#wizardsObject (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

Returns:

  • (Boolean)


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

Parameters:

  • version (Float)

    the version to load defaults for



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