Class: Fusuma::Config
- Inherits:
-
Object
- Object
- Fusuma::Config
- Includes:
- Singleton
- Defined in:
- lib/fusuma/config.rb,
lib/fusuma/config/index.rb
Overview
read keymap from yaml file
Defined Under Namespace
Classes: Index
Instance Attribute Summary collapse
-
#custom_path ⇒ Object
Returns the value of attribute custom_path.
-
#keymap ⇒ Object
readonly
Returns the value of attribute keymap.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #reload ⇒ Object
- #search(index) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
27 28 29 30 31 32 |
# File 'lib/fusuma/config.rb', line 27 def initialize @custom_path = nil @cache = nil @keymap = nil reload end |
Instance Attribute Details
#custom_path ⇒ Object
Returns the value of attribute custom_path.
25 26 27 |
# File 'lib/fusuma/config.rb', line 25 def custom_path @custom_path end |
#keymap ⇒ Object (readonly)
Returns the value of attribute keymap.
24 25 26 |
# File 'lib/fusuma/config.rb', line 24 def keymap @keymap end |
Class Method Details
.custom_path=(new_path) ⇒ Object
19 20 21 |
# File 'lib/fusuma/config.rb', line 19 def custom_path=(new_path) instance.custom_path = new_path end |
.search(keys) ⇒ Object
15 16 17 |
# File 'lib/fusuma/config.rb', line 15 def search(keys) instance.search(keys) end |
Instance Method Details
#reload ⇒ Object
39 40 41 42 43 44 |
# File 'lib/fusuma/config.rb', line 39 def reload @cache = nil @keymap = YAML.load_file(file_path).deep_symbolize_keys MultiLogger.info "reload config : #{file_path}" self end |
#search(index) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fusuma/config.rb', line 47 def search(index) cache(index.cache_key) do index.keys.reduce(keymap) do |location, key| if location.is_a?(Hash) begin if key.skippable location.fetch(key.symbol, location) else location.fetch(key.symbol, nil) end end else location end end end end |