Sha256: 5bb4020de171fa90a21e6169019f8a7f2d363d1740f39da11cf68b7041c5c754
Contents?: true
Size: 1.63 KB
Versions: 39
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true require 'active_support/concern' require 'eac_ruby_utils/simple_cache' require 'eac_ruby_utils/patches/object/if_present' module EacRubyUtils class CommonConcern CLASS_METHODS_MODULE_NAME = 'ClassMethods' INSTANCE_METHODS_MODULE_NAME = 'InstanceMethods' attr_reader :after_callback def initialize(&after_callback) @after_callback = after_callback end def setup(a_module) Setup.new(self, a_module).run end class Setup include ::EacRubyUtils::SimpleCache attr_reader :a_module, :common_concern def initialize(common_concern, a_module) @common_concern = common_concern @a_module = a_module end def run setup = self a_module.extend(::ActiveSupport::Concern) a_module.included do %w[class_methods instance_methods after_callback].each do |suffix| setup.send("setup_#{suffix}", self) end end end def setup_class_methods(base) class_methods_module.if_present { |v| base.extend v } end def setup_instance_methods(base) instance_methods_module.if_present { |v| base.include v } end def setup_after_callback(base) common_concern.after_callback.if_present do |v| base.instance_eval(&v) end end def class_methods_module_uncached a_module.const_get(CLASS_METHODS_MODULE_NAME) rescue NameError nil end def instance_methods_module_uncached a_module.const_get(INSTANCE_METHODS_MODULE_NAME) rescue NameError nil end end end end
Version data entries
39 entries across 39 versions & 3 rubygems