lib/fusuma/config.rb in fusuma-0.9.2 vs lib/fusuma/config.rb in fusuma-0.10.1

- old
+ new

@@ -4,24 +4,24 @@ # read keymap from yaml file class Config include Singleton class << self - def command(event_trigger) - instance.command(event_trigger) + def command(command_executor) + instance.command(command_executor) end - def shortcut(event_trigger) - instance.shortcut(event_trigger) + def shortcut(command_executor) + instance.shortcut(command_executor) end - def threshold(action_type) - instance.threshold(action_type) + def threshold(command_executor) + instance.threshold(command_executor) end - def interval(action_type) - instance.interval(action_type) + def interval(command_executor) + instance.interval(command_executor) end def reload instance.reload end @@ -29,42 +29,50 @@ attr_reader :keymap attr_accessor :custom_path def initialize - @custom_path = nil + self.custom_path = nil reload end def reload @cache = nil @keymap = YAML.load_file(file_path) self end - def command(event_trigger) - seek_index = [*action_index(event_trigger), 'command'] - cache(seek_index) { search_config(keymap, seek_index) } + def command(command_executor) + seek_index = [*event_index(command_executor), 'command'] + search_config_cached(seek_index) end - def shortcut(event_trigger) - seek_index = [*action_index(event_trigger), 'shortcut'] - cache(seek_index) { search_config(keymap, seek_index) } + def shortcut(command_executor) + seek_index = [*event_index(command_executor), 'shortcut'] + search_config_cached(seek_index) end - def threshold(action_type) - seek_index = ['threshold', action_type] - cache(seek_index) { search_config(keymap, seek_index) } || 1 + def threshold(command_executor) + seek_index_specific = [*event_index(command_executor), 'threshold'] + seek_index_global = ['threshold', command_executor.event_type] + search_config_cached(seek_index_specific) || + search_config_cached(seek_index_global) || 1 end - def interval(action_type) - seek_index = ['interval', action_type] - cache(seek_index) { search_config(keymap, seek_index) } || 1 + def interval(command_executor) + seek_index_specific = [*event_index(command_executor), 'interval'] + seek_index_global = ['interval', command_executor.event_type] + search_config_cached(seek_index_specific) || + search_config_cached(seek_index_global) || 1 end private + def search_config_cached(seek_index) + cache(seek_index) { search_config(keymap, seek_index) } + end + def search_config(keymap_node, seek_index) if seek_index == [] return nil if keymap_node.is_a? Hash return keymap_node end @@ -96,14 +104,14 @@ def expand_default_path(filename) File.expand_path "../../#{filename}", __FILE__ end - def action_index(event_trigger) - action_type = event_trigger.action_type - finger = event_trigger.finger - direction = event_trigger.direction - [action_type, finger, direction] + def event_index(command_executor) + event_type = command_executor.event_type + finger = command_executor.finger + direction = command_executor.direction + [event_type, finger, direction] end def cache(key) @cache ||= {} key = key.join(',') if key.is_a? Array