Sha256: 16da21fe6a6f85c4c1333e14438d8fe647f5cac6381e3ec682014d7eae872ad3
Contents?: true
Size: 1001 Bytes
Versions: 4
Compression:
Stored size: 1001 Bytes
Contents
# frozen_string_literal: true module Lite module Command HOOKS = [ :after_initialize, :before_validation, :after_validation, :before_execution, :after_execution, *STATUSES.map { |s| :"on_#{s}" }, *STATES.map { |s| :"on_#{s}" } ].freeze module Internals module Hooks def self.included(base) base.extend ClassMethods end module ClassMethods def hooks @hooks ||= Utils.cmd_try(superclass, :hooks).dup || {} end HOOKS.each do |h| define_method(h) do |*method_names, &block| method_names << block if block_given? method_names.each { |mn| (hooks[h] ||= []) << mn } end end end private def run_hooks(hook) hooks = self.class.hooks[hook] return if hooks.nil? hooks.each { |h| Utils.cmd_call(self, h) } end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems