Class: InertiaRails::Configuration
- Inherits:
-
Object
- Object
- InertiaRails::Configuration
- Defined in:
- lib/inertia_rails/configuration.rb
Constant Summary collapse
- DEFAULTS =
{ # Whether to combine hashes with the same keys instead of replacing them. deep_merge_shared_data: false, # Overrides Rails default rendering behavior to render using Inertia by default. default_render: false, # Allows the user to hook into the default rendering behavior and change it to fit their needs component_path_resolver: ->(path:, action:) { "#{path}/#{action}" }, # DEPRECATED: Let Rails decide which layout should be used based on the # controller configuration. layout: true, # SSR options. ssr_enabled: false, ssr_url: 'http://localhost:13714', # Used to detect version drift between server and client. version: nil, }.freeze
- OPTION_NAMES =
DEFAULTS.keys.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #bind_controller(controller) ⇒ Object
- #component_path_resolver(path:, action:) ⇒ Object
- #freeze ⇒ Object
-
#initialize(controller: nil, **attrs) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(config) ⇒ Object
- #merge!(config) ⇒ Object
-
#with_defaults(config) ⇒ Object
Internal: Finalizes the configuration for a specific controller.
Constructor Details
#initialize(controller: nil, **attrs) ⇒ Configuration
Returns a new instance of Configuration.
32 33 34 35 36 37 38 39 |
# File 'lib/inertia_rails/configuration.rb', line 32 def initialize(controller: nil, **attrs) @controller = controller @options = attrs.extract!(*OPTION_NAMES) unless attrs.empty? raise ArgumentError, "Unknown options for #{self.class}: #{attrs.keys}" end end |
Class Method Details
.default ⇒ Object
78 79 80 |
# File 'lib/inertia_rails/configuration.rb', line 78 def self.default new(**DEFAULTS) end |
Instance Method Details
#bind_controller(controller) ⇒ Object
41 42 43 |
# File 'lib/inertia_rails/configuration.rb', line 41 def bind_controller(controller) Configuration.new(**@options, controller: controller) end |
#component_path_resolver(path:, action:) ⇒ Object
65 66 67 |
# File 'lib/inertia_rails/configuration.rb', line 65 def component_path_resolver(path:, action:) @options[:component_path_resolver].call(path:, action:) end |
#freeze ⇒ Object
45 46 47 48 |
# File 'lib/inertia_rails/configuration.rb', line 45 def freeze @options.freeze super end |
#merge(config) ⇒ Object
55 56 57 |
# File 'lib/inertia_rails/configuration.rb', line 55 def merge(config) Configuration.new(**@options.merge(config.)) end |
#merge!(config) ⇒ Object
50 51 52 53 |
# File 'lib/inertia_rails/configuration.rb', line 50 def merge!(config) @options.merge!(config.) self end |
#with_defaults(config) ⇒ Object
Internal: Finalizes the configuration for a specific controller.
60 61 62 63 |
# File 'lib/inertia_rails/configuration.rb', line 60 def with_defaults(config) @options = config..merge(@options) freeze end |