Class: Fusuma::Config
- Inherits:
-
Object
- Object
- Fusuma::Config
- Includes:
- Singleton
- Defined in:
- lib/fusuma/config.rb,
lib/fusuma/config/index.rb,
lib/fusuma/config/searcher.rb,
lib/fusuma/config/yaml_duplication_checker.rb
Overview
read keymap from yaml file
Defined Under Namespace
Modules: YAMLDuplicationChecker Classes: Index, InvalidFileError, NotFoundError, Searcher
Instance Attribute Summary collapse
-
#custom_path ⇒ Object
Returns the value of attribute custom_path.
-
#keymap ⇒ Object
readonly
Returns the value of attribute keymap.
-
#searcher ⇒ Object
readonly
Returns the value of attribute searcher.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_execute_key(index) ⇒ Object
Symbol.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #reload ⇒ Object
- #search(index) ⇒ Object
-
#validate(path) ⇒ Hash
If check passes.
Constructor Details
Instance Attribute Details
#custom_path ⇒ Object
Returns the value of attribute custom_path.
35 36 37 |
# File 'lib/fusuma/config.rb', line 35 def custom_path @custom_path end |
#keymap ⇒ Object (readonly)
Returns the value of attribute keymap.
35 36 37 |
# File 'lib/fusuma/config.rb', line 35 def keymap @keymap end |
#searcher ⇒ Object (readonly)
Returns the value of attribute searcher.
35 36 37 |
# File 'lib/fusuma/config.rb', line 35 def searcher @searcher end |
Class Method Details
.custom_path=(new_path) ⇒ Object
30 31 32 |
# File 'lib/fusuma/config.rb', line 30 def custom_path=(new_path) instance.custom_path = new_path end |
.find_execute_key(index) ⇒ Object
26 27 28 |
# File 'lib/fusuma/config.rb', line 26 def find_execute_key(index) instance.find_execute_key(index) end |
.search(index) ⇒ Object
22 23 24 |
# File 'lib/fusuma/config.rb', line 22 def search(index) instance.search(index) end |
Instance Method Details
#find_execute_key(index) ⇒ Object
Returns Symbol.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fusuma/config.rb', line 81 def find_execute_key(index) @execute_keys ||= Plugin::Executors::Executor.plugins.map do |executor| executor.new.execute_keys end.flatten execute_params = search(index) return if execute_params.nil? || !execute_params.is_a?(Hash) @execute_keys.find { |k| execute_params.keys.include?(k) } end |
#reload ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/fusuma/config.rb', line 48 def reload @searcher = Searcher.new path = find_filepath MultiLogger.info "reload config: #{path}" @keymap = validate(path) self end |
#search(index) ⇒ Object
75 76 77 |
# File 'lib/fusuma/config.rb', line 75 def search(index) @searcher.search_with_cache(index, location: keymap) end |
#validate(path) ⇒ Hash
Returns If check passes.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fusuma/config.rb', line 58 def validate(path) duplicates = [] YAMLDuplicationChecker.check(File.read(path), path) do |ignored, duplicate| MultiLogger.error "#{path}: #{ignored.value} is duplicated" duplicates << duplicate.value end raise InvalidFileError, "Detect duplicate keys #{duplicates}" unless duplicates.empty? yamls = YAML.load_stream(File.read(path)).compact yamls.map(&:deep_symbolize_keys) rescue StandardError => e MultiLogger.error e. raise InvalidFileError, e. end |