Class: Shojiku::Settings
- Inherits:
-
Object
- Object
- Shojiku::Settings
- Defined in:
- lib/shojiku/settings.rb
Overview
One client's resolved configuration, plus the collaborators built from it.
Config answers "what was configured"; this answers "what does THIS client use", which is the merge of the process-wide defaults with the arguments the client was constructed with. Keeping it out of Client keeps the precedence rules in one readable place instead of spread across a constructor.
Everything is built lazily and memoized: a bytes-first application never configures a template root, and demanding one at construction would refuse a legitimate client.
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
Instance Method Summary collapse
- #env ⇒ Object
- #font_dirs ⇒ Object
-
#initialize(**overrides) ⇒ Settings
constructor
A new instance of Settings.
- #library ⇒ Object
- #locale_dirs ⇒ Object
- #lockdown ⇒ Object
- #log ⇒ Object
-
#template_root ⇒ Object
The template root, or nil when nothing configured one.
-
#with_lang(lang) ⇒ Object
A copy that renders in
lang, for Client#with_lang.
Constructor Details
Instance Attribute Details
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
16 17 18 |
# File 'lib/shojiku/settings.rb', line 16 def lang @lang end |
Instance Method Details
#env ⇒ Object
32 33 34 |
# File 'lib/shojiku/settings.rb', line 32 def env @env ||= Env.new(enabled: @config.env) end |
#font_dirs ⇒ Object
48 49 50 |
# File 'lib/shojiku/settings.rb', line 48 def font_dirs @font_dirs ||= @config.font_dirs || env.paths("SHOJIKU_FONT_DIR") end |
#library ⇒ Object
44 45 46 |
# File 'lib/shojiku/settings.rb', line 44 def library @library ||= Library.new(path: @config.library, env: env, log: log) end |
#locale_dirs ⇒ Object
52 53 54 |
# File 'lib/shojiku/settings.rb', line 52 def locale_dirs @locale_dirs ||= @config.locale_dirs || env.paths("SHOJIKU_LOCALE_DIR") end |
#lockdown ⇒ Object
40 41 42 |
# File 'lib/shojiku/settings.rb', line 40 def lockdown @lockdown ||= Lockdown.new(strict: @config.strict, providers: @config.providers) end |
#log ⇒ Object
36 37 38 |
# File 'lib/shojiku/settings.rb', line 36 def log @log ||= Log.new(@config.logger) end |
#template_root ⇒ Object
The template root, or nil when nothing configured one.
defined? rather than ||= because nil is a legitimate answer here and
would otherwise be re-resolved on every call.
60 61 62 63 64 65 |
# File 'lib/shojiku/settings.rb', line 60 def template_root return @template_root if defined?(@template_root) root = @config.templates || env["SHOJIKU_TEMPLATE_ROOT"] @template_root = root ? TemplateRoot.new(root) : nil end |
#with_lang(lang) ⇒ Object
A copy that renders in lang, for Client#with_lang. Everything
already built — the opened library, the template root, the lockdown —
is carried over by dup, so deriving a client re-opens nothing.
26 27 28 29 30 |
# File 'lib/shojiku/settings.rb', line 26 def with_lang(lang) copy = dup copy.override_lang(lang) copy end |