module Polyseerio::Agent::Helper
Public Class Methods
create_handler(iteratee)
click to toggle source
Returns a handler function.
# File lib/agent/helper.rb, line 23 def self.create_handler(iteratee) proc do |map, client, config, type, *args| if map.key? type.to_sym if config.key? type # to_sym? Polyseerio.log 'debug', "Performing handler work for: #{type}." # TODO: unit-test passed args work = config.fetch(type) .map(&iteratee.call(map.fetch(type), client, *args)) Concurrent::Promise.zip(*work) else Concurrent::Promise.fulfill [] end else Concurrent::Promise.reject('Could not find a handler type: ' \ "#{type}.") end end end
create_subtype_iterator(handlers, iteratee, *args)
click to toggle source
Returns an iterator for a handler subtype.
# File lib/agent/helper.rb, line 11 def self.create_subtype_iterator(handlers, iteratee, *args) proc do |key, value| if handlers.key? key.to_sym # TODO: unit-test to_sym iteratee.call(handlers, key, value, *args) else Concurrent::Promise.reject('Could not find a handler subtype: ' \ "#{key}.") end end end
extract_handler_options(options)
click to toggle source
Extracts handler options and then filters them based on if they are enabled or not. TODO: unit-test or integration-test
# File lib/agent/helper.rb, line 118 def self.extract_handler_options(options) options = Handler.extract_options options filter_handlers options end
filter_enabled_handler_options(options)
click to toggle source
Given handler options, enabled subtype options are returned.
# File lib/agent/helper.rb, line 103 def self.filter_enabled_handler_options(options) options.each_with_object({}, &reduce_handler_option) end
filter_handlers(options)
click to toggle source
Given agent options, handlers options are returned.
# File lib/agent/helper.rb, line 108 def self.filter_handlers(options) options.each_with_object({}) do |(name, config), acc| acc[name] = filter_enabled_handler_options config acc end end
generate_name()
click to toggle source
Returns a unique name.
# File lib/agent/helper.rb, line 89 def self.generate_name 'ruby-instance' end
handle?(value)
click to toggle source
Determines if a handler configuration should be handled.
# File lib/agent/helper.rb, line 125 def self.handle?(value) return value if value == true if Functional::TypeCheck::Type?(value, Hash) && (value.key? :enabled) return value[:enabled] end false end
reduce_handler_option()
click to toggle source
Reduce handler options based on if they are enabled.
# File lib/agent/helper.rb, line 94 def self.reduce_handler_option proc do |(name, config), acc| acc[name] = config if handle? config acc end end
resolve_name(config)
click to toggle source
Given an agent config a name will be returned.
# File lib/agent/helper.rb, line 136 def self.resolve_name(config) return config[:name] if config.key?(:name) && !config[:name].nil? generate_name end
setup_with_handler(*args)
click to toggle source
Sets up a handler type.
# File lib/agent/helper.rb, line 79 def self.setup_with_handler(*args) create_handler(@setup).curry.call(*args) end
teardown_with_handler(*args)
click to toggle source
Tears down a handler type.
# File lib/agent/helper.rb, line 84 def self.teardown_with_handler(*args) create_handler(@teardown).curry.call(*args) end