Sha256: 2f5c57bf12e0cb62c6c72a815df02090287d70f52c5de59995664b75b1e76472
Contents?: true
Size: 993 Bytes
Versions: 2
Compression:
Stored size: 993 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.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.call(self, h) } end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lite-command-3.2.1 | lib/lite/command/internals/hooks.rb |
lite-command-3.2.0 | lib/lite/command/internals/hooks.rb |