Class: TkWrapper::Widgets::Base::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/widgets/base/manager.rb

Overview

manages widgets and their global configurations

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



5
6
7
8
# File 'lib/widgets/base/manager.rb', line 5

def initialize
  @configuration_matchers = { regex: {}, map: {} }
  @modification_matchers = { regex: {}, map: {} }
end

Instance Method Details

#add_configurations(matcher = nil, config = nil, **configs) ⇒ Object



10
11
12
13
14
# File 'lib/widgets/base/manager.rb', line 10

def add_configurations(matcher = nil, config = nil, **configs)
  add_matcher(matcher, config, @configuration_matchers) if config

  configs.each { |mat, cfg| add_matcher(mat, cfg, @configuration_matchers) }
end

#add_modification(matcher, &callback) ⇒ Object



16
17
18
# File 'lib/widgets/base/manager.rb', line 16

def add_modification(matcher, &callback)
  add_matcher(matcher, callback, @modification_matchers)
end

#configurations(widget) ⇒ Object



20
21
22
23
# File 'lib/widgets/base/manager.rb', line 20

def configurations(widget)
  configs = find_matching_items(widget.ids, @configuration_matchers)
  configs.map { |config| config[0] }
end

#execute_modifications(widget) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/widgets/base/manager.rb', line 25

def execute_modifications(widget)
  callbacks = find_matching_items(widget.ids, @modification_matchers)
  callbacks.each do |callback|
    callback, match = callback
    match ? callback.call(widget, match) : callback.call(widget)
  end
end