Class: Fusuma::Plugin::Remap::LayerManager
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Remap::LayerManager
- Includes:
- Singleton
- Defined in:
- lib/fusuma/plugin/remap/layer_manager.rb
Overview
Set layer sent from pipe
Instance Attribute Summary collapse
-
#current_layer ⇒ Object
readonly
Returns the value of attribute current_layer.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
-
#find_mapping(layer) ⇒ Hash
Find remap layer from config.
-
#initialize ⇒ LayerManager
constructor
A new instance of LayerManager.
-
#receive_layer ⇒ Hash
Read layer from pipe and update @current_layer.
- #send_layer(layer:, remove: false) ⇒ Object
Constructor Details
#initialize ⇒ LayerManager
Returns a new instance of LayerManager.
13 14 15 16 17 18 19 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 13 def initialize @layers = {} @reader, @writer = IO.pipe @current_layer = {} # preserve order @last_layer = nil @last_remove = nil end |
Instance Attribute Details
#current_layer ⇒ Object (readonly)
Returns the value of attribute current_layer.
11 12 13 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 11 def current_layer @current_layer end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
11 12 13 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 11 def layers @layers end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
11 12 13 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 11 def reader @reader end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
11 12 13 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 11 def writer @writer end |
Instance Method Details
#find_mapping(layer) ⇒ Hash
Find remap layer from config
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 64 def find_mapping(layer) @layers[layer] ||= begin result = nil _ = Fusuma::Config::Searcher.find_context(layer) do result = Fusuma::Config.search(Fusuma::Config::Index.new(:remap)) next unless result result = result.deep_transform_keys { |key| key.upcase.to_sym } end result || {} end end |
#receive_layer ⇒ Hash
Read layer from pipe and update @current_layer
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 38 def receive_layer @layer_unpacker ||= MessagePack::Unpacker.new(@reader) data = @layer_unpacker.unpack return unless data.is_a? Hash data = data.deep_symbolize_keys layer = data[:layer] # e.g { thumbsense: true } remove = data[:remove] # e.g true # update @current_layer if remove MultiLogger.debug "Remove layer: #{layer}" @current_layer.delete_if { |k, _v| layer.key?(k) } else MultiLogger.debug "Add layer: #{layer}" # If duplicate keys exist, order of keys is preserved @current_layer.merge!(layer) end @current_layer end |
#send_layer(layer:, remove: false) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/fusuma/plugin/remap/layer_manager.rb', line 23 def send_layer(layer:, remove: false) return if (@last_layer == layer) && (@last_remove == remove) @last_layer = layer @last_remove = remove @writer.write({layer: layer, remove: remove}.to_msgpack) end |