Class: Funicular::Configuration

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

Overview

Holds runtime configuration for the funicular gem.

The most important setting is which PicoRuby.wasm artifact the picoruby_include_tag helper should reference, per Rails environment.

Possible source values:

:local_debug - serve the debug build vendored into the gem and
               installed under public/picoruby/debug/
:local_dist  - serve the production (dist) build vendored into the
               gem and installed under public/picoruby/dist/
:cdn         - load from jsDelivr at
               https://cdn.jsdelivr.net/npm/@picoruby/wasm-wasi@VERSION/dist/init.iife.js

Defaults are sensible for most apps:

development -> :local_debug
test        -> :local_debug
production  -> :local_dist

Switch production to :cdn if you would rather not host the wasm yourself.

Constant Summary collapse

SOURCES =
%i[local_debug local_dist cdn].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



31
32
33
34
35
36
# File 'lib/funicular/configuration.rb', line 31

def initialize
  @development_source = :local_debug
  @test_source        = :local_debug
  @production_source  = :local_dist
  @cdn_version        = nil
end

Instance Attribute Details

#cdn_versionObject

The @picoruby/wasm-wasi version to use when source is :cdn. Falls back to the version of the wasm artifacts vendored in this gem.



62
63
64
# File 'lib/funicular/configuration.rb', line 62

def cdn_version
  @cdn_version || Funicular.vendored_wasm_version
end

#development_sourceObject

Returns the value of attribute development_source.



28
29
30
# File 'lib/funicular/configuration.rb', line 28

def development_source
  @development_source
end

#production_sourceObject

Returns the value of attribute production_source.



28
29
30
# File 'lib/funicular/configuration.rb', line 28

def production_source
  @production_source
end

#test_sourceObject

Returns the value of attribute test_source.



28
29
30
# File 'lib/funicular/configuration.rb', line 28

def test_source
  @test_source
end

Instance Method Details

#source_for(env_name) ⇒ Object

Returns the configured source for a given Rails environment name. Unknown environments fall back to development_source.



52
53
54
55
56
57
58
# File 'lib/funicular/configuration.rb', line 52

def source_for(env_name)
  case env_name.to_s
  when "production" then @production_source
  when "test"       then @test_source
  else                   @development_source
  end
end