Class: Fusuma::Config

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_pathObject

Returns the value of attribute custom_path.



25
26
27
# File 'lib/fusuma/config.rb', line 25

def custom_path
  @custom_path
end

#keymapObject (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

#reloadObject



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

Parameters:



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