Sha256: f9d57be2b0f51985b41d6bff7a67982187dbce099970de77a37c6155cfbe1af1
Contents?: true
Size: 1.65 KB
Versions: 44
Compression:
Stored size: 1.65 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_constructor def initialize(common_constructor, a_module) @common_constructor = common_constructor @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_constructor.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
44 entries across 44 versions & 3 rubygems