class Kontena::Callback
Attributes
command[R]
Public Class Methods
callbacks()
click to toggle source
# File lib/kontena/callback.rb, line 39 def self.callbacks @@callbacks ||= {} end
matches_commands(*commands)
click to toggle source
Register callback for command types it is supposed to run with.
# File lib/kontena/callback.rb, line 10 def self.matches_commands(*commands) cmd_types = {} commands.each do |cmd| cmd_class, cmd_type = cmd.split(' ', 2) if cmd_class == '*' cmd_class = :all end if cmd_type.nil? || cmd_type == '*' cmd_type = :all else cmd_type = cmd_type.to_sym end cmd_types[cmd_class.to_sym] ||= [] cmd_types[cmd_class.to_sym] << cmd_type end # Finally it should be normalized into a hash that looks like :cmd_class => :cmd_type, :app => :init, :grid => :all cmd_types.each do |cmd_class, cmd_types| cmd_types.each do |cmd_type| Kontena::Callback.callbacks[cmd_class] ||= {} Kontena::Callback.callbacks[cmd_class][cmd_type] ||= [] Kontena::Callback.callbacks[cmd_class][cmd_type] << self end end end
new(command)
click to toggle source
# File lib/kontena/callback.rb, line 5 def initialize(command) @command = command end
run_callbacks(cmd_type, state, obj)
click to toggle source
# File lib/kontena/callback.rb, line 43 def self.run_callbacks(cmd_type, state, obj) [cmd_type.last, :all].compact.uniq.each do |cmdtype| [cmd_type.first, :all].compact.uniq.each do |cmdclass| callbacks.fetch(cmdclass, {}).fetch(cmdtype, []).each do |klass| if klass.instance_methods.include?(state) cb = klass.new(obj) if cb.send(state).kind_of?(FalseClass) Kontena.logger.debug { "Execution aborted by #{klass}" } exit 1 end end end end end end