Class: Weft::Configuration
- Inherits:
-
Object
- Object
- Weft::Configuration
- Defined in:
- lib/weft/configuration.rb
Instance Attribute Summary collapse
-
#component_path ⇒ Object
Returns the value of attribute component_path.
-
#error_component ⇒ Object
Lazy defaults — resolved on first read so Weft::Defaults classes load before the Configuration class is required.
- #error_page ⇒ Object
-
#htmx_errors ⇒ Object
Returns the value of attribute htmx_errors.
-
#include_htmx ⇒ Object
Returns the value of attribute include_htmx.
-
#include_sse_ext ⇒ Object
Returns the value of attribute include_sse_ext.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
- #not_found_component ⇒ Object
- #not_found_page ⇒ Object
-
#push_attempts ⇒ Object
Returns the value of attribute push_attempts.
-
#router_logging ⇒ Object
Returns the value of attribute router_logging.
-
#stream_suffix ⇒ Object
Returns the value of attribute stream_suffix.
-
#verbose_error_pages ⇒ Object
Returns the value of attribute verbose_error_pages.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
private
Instantiated internally by configuration.
-
#refresh_stale_classes! ⇒ Object
Re-resolve the class-valued knobs after a code reload.
-
#resolved_log_level ⇒ Object
Resolves the configured log_level symbol to its Logger severity constant (e.g. :warn -> Logger::WARN).
-
#static_assets(name: nil, root: nil, from: nil) ⇒ Object
Register a directory to serve as static assets at a URL prefix, under a logical bundle name.
Constructor Details
#initialize ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiated internally by Weft.configuration. Configure Weft via
Weft.configure { |c| ... } rather than constructing this directly.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/weft/configuration.rb', line 27 def initialize @component_path = DEFAULT_COMPONENT_PATH @include_htmx = true @include_sse_ext = :auto @router_logging = false @verbose_error_pages = true @htmx_errors = :fragment @log_level = :info @push_attempts = 3 @stream_suffix = "_stream" @static_assets = {} end |
Instance Attribute Details
#component_path ⇒ Object
Returns the value of attribute component_path.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def component_path @component_path end |
#error_component ⇒ Object
Lazy defaults — resolved on first read so Weft::Defaults classes load before the Configuration class is required. Assignment sticks.
136 137 138 |
# File 'lib/weft/configuration.rb', line 136 def error_component @error_component ||= Weft::Defaults::ErrorComponent end |
#error_page ⇒ Object
140 141 142 |
# File 'lib/weft/configuration.rb', line 140 def error_page @error_page ||= Weft::Defaults::ErrorPage end |
#htmx_errors ⇒ Object
Returns the value of attribute htmx_errors.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def htmx_errors @htmx_errors end |
#include_htmx ⇒ Object
Returns the value of attribute include_htmx.
21 22 23 |
# File 'lib/weft/configuration.rb', line 21 def include_htmx @include_htmx end |
#include_sse_ext ⇒ Object
Returns the value of attribute include_sse_ext.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def include_sse_ext @include_sse_ext end |
#log_level ⇒ Object
Returns the value of attribute log_level.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def log_level @log_level end |
#not_found_component ⇒ Object
148 149 150 |
# File 'lib/weft/configuration.rb', line 148 def not_found_component @not_found_component ||= Weft::Defaults::NotFoundComponent end |
#not_found_page ⇒ Object
144 145 146 |
# File 'lib/weft/configuration.rb', line 144 def not_found_page @not_found_page ||= Weft::Defaults::NotFoundPage end |
#push_attempts ⇒ Object
Returns the value of attribute push_attempts.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def push_attempts @push_attempts end |
#router_logging ⇒ Object
Returns the value of attribute router_logging.
21 22 23 |
# File 'lib/weft/configuration.rb', line 21 def router_logging @router_logging end |
#stream_suffix ⇒ Object
Returns the value of attribute stream_suffix.
20 21 22 |
# File 'lib/weft/configuration.rb', line 20 def stream_suffix @stream_suffix end |
#verbose_error_pages ⇒ Object
Returns the value of attribute verbose_error_pages.
21 22 23 |
# File 'lib/weft/configuration.rb', line 21 def verbose_error_pages @verbose_error_pages end |
Instance Method Details
#refresh_stale_classes! ⇒ Object
Re-resolve the class-valued knobs after a code reload. A knob assigned at boot holds that moment's class object; a reloader that redefines the constant would otherwise leave the knob serving the stale definition until restart. The configure_autoloading reload hook calls this after each reload; hand-rolled reloaders should call it from their own hook. A knob whose constant no longer resolves (mid-unload, or the class was deleted) keeps its last-known class.
159 160 161 162 163 164 165 166 167 |
# File 'lib/weft/configuration.rb', line 159 def refresh_stale_classes! CLASS_KNOBS.each do |knob| klass = instance_variable_get(:"@#{knob}") next unless klass.is_a?(Class) && klass.name current = klass.name.safe_constantize instance_variable_set(:"@#{knob}", current) if current.is_a?(Class) && !current.equal?(klass) end end |
#resolved_log_level ⇒ Object
Resolves the configured log_level symbol to its Logger severity constant (e.g. :warn -> Logger::WARN). Used by Weft.configure to set logger.level.
105 106 107 |
# File 'lib/weft/configuration.rb', line 105 def resolved_log_level LOG_LEVELS.fetch(@log_level) end |
#static_assets(name: nil, root: nil, from: nil) ⇒ Object
Register a directory to serve as static assets at a URL prefix, under
a logical bundle name. The bundle name is the stable reference used at
call sites (register_stylesheet "css/app.css", assets: :app); the
root/from pair can be reconfigured (e.g. from env vars in production)
without touching call sites.
Multi-call: each call adds a => {root:, from:} entry. Raises ArgumentError on duplicate name or duplicate root.
c.static_assets root: "/static", from: File.join(APP_ROOT, "public")
# name: defaults to :default — call sites without an `assets:` kwarg
# implicitly resolve against this bundle.
c.static_assets name: :vendor, root: "/vendor",
from: File.join(APP_ROOT, "vendor", "assets")
Called with no arguments, returns a copy of the registered bundles as a hash (name => from:). Used by the apply step and the page-side resolve_asset_url logic.
128 129 130 131 132 |
# File 'lib/weft/configuration.rb', line 128 def static_assets(name: nil, root: nil, from: nil) return @static_assets.transform_values(&:dup) if name.nil? && root.nil? && from.nil? register_static_assets_bundle(name: name, root: root, from: from) end |