Class: Fronde::Config::Store
- Inherits:
-
Object
- Object
- Fronde::Config::Store
- Includes:
- Lisp, Singleton
- Defined in:
- lib/fronde/config.rb
Overview
Wrapper for configuration
This class is a singleton interface, which share the static website being build settings among different steps or tasks.
It expects the website author to holds their custom settings in a YAML file named ~config.yml~ available at the root of their project.
For example, with the given config file:
#+begin_src
title: My website author: Alice Doe #+end_src
Settings will be available like this:
#+begin_src Fronde::CONFIG.get(‘author’)
> “Alice Doe”
#+end_src
Instance Attribute Summary collapse
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
-
#get(setting, default = nil) ⇒ Object
Return a named setting.
-
#initialize ⇒ Store
constructor
A new instance of Store.
-
#load_sources ⇒ Array
Return the qualified projects sources list.
-
#load_test(config) ⇒ Fronde::Config::Store
Load the given settings as if they comes from the ~config.yml~ file.
-
#reset ⇒ Object
Reset settings.
-
#settings ⇒ Hash
Access the current website settings.
Methods included from Lisp
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fronde/config.rb', line 40 def initialize @default_settings = { 'author' => ENV['USER'] || '', 'domain' => '', 'lang' => Fronde::Config::Helpers.extract_lang_from_env('en'), 'html_public_folder' => 'public_html', 'gemini_public_folder' => 'public_gmi', 'templates' => [], 'theme' => 'default' }.freeze # Do not load sources now to avoid dependency loop on config @sources = nil @config = load_settings end |
Instance Attribute Details
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
38 39 40 |
# File 'lib/fronde/config.rb', line 38 def sources @sources end |
Instance Method Details
#get(setting, default = nil) ⇒ Object
Return a named setting.
~setting~ may be a ~String~ or an ~Array~.
If the given ~setting~ name is an Array, this method will behave as ~Hash::dig~.
If no value is found for the given setting, ~default~ will be returned.
76 77 78 79 80 81 82 83 |
# File 'lib/fronde/config.rb', line 76 def get(setting, default = nil) if setting.is_a? Array value = @config.dig(*setting) else value = @config[setting] end value || default end |
#load_sources ⇒ Array
Return the qualified projects sources list.
120 121 122 123 124 |
# File 'lib/fronde/config.rb', line 120 def load_sources return @sources if @sources @sources = remove_inclusion(remove_duplicate(build_sources)) end |
#load_test(config) ⇒ Fronde::Config::Store
110 111 112 113 114 115 |
# File 'lib/fronde/config.rb', line 110 def load_test(config) @config = @default_settings.merge config @sources = nil @sources = load_sources self end |
#reset ⇒ Object
93 94 95 96 97 98 |
# File 'lib/fronde/config.rb', line 93 def reset # Reload config, taking default settings into account @config = load_settings @sources = nil @sources = load_sources end |
#settings ⇒ Hash
Access the current website settings
59 60 61 |
# File 'lib/fronde/config.rb', line 59 def settings @config end |