Class: EacRubyUtils::CommonConcern::Setup

Inherits:
Object
  • Object
show all
Includes:
SimpleCache
Defined in:
lib/eac_ruby_utils/common_concern.rb

Constant Summary

Constants included from SimpleCache

SimpleCache::UNCACHED_METHOD_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleCache

#method_missing, #reset_cache, #respond_to_missing?

Constructor Details

#initialize(common_concern, a_module) ⇒ Setup

Returns a new instance of Setup.



26
27
28
29
# File 'lib/eac_ruby_utils/common_concern.rb', line 26

def initialize(common_concern, a_module)
  @common_concern = common_concern
  @a_module = a_module
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EacRubyUtils::SimpleCache

Instance Attribute Details

#a_moduleObject (readonly)

Returns the value of attribute a_module.



24
25
26
# File 'lib/eac_ruby_utils/common_concern.rb', line 24

def a_module
  @a_module
end

#common_concernObject (readonly)

Returns the value of attribute common_concern.



24
25
26
# File 'lib/eac_ruby_utils/common_concern.rb', line 24

def common_concern
  @common_concern
end

Instance Method Details

#class_methods_module_uncachedObject



55
56
57
58
59
# File 'lib/eac_ruby_utils/common_concern.rb', line 55

def class_methods_module_uncached
  a_module.const_get(CLASS_METHODS_MODULE_NAME)
rescue NameError
  nil
end

#instance_methods_module_uncachedObject



61
62
63
64
65
# File 'lib/eac_ruby_utils/common_concern.rb', line 61

def instance_methods_module_uncached
  a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
rescue NameError
  nil
end

#runObject



31
32
33
34
35
36
37
38
39
# File 'lib/eac_ruby_utils/common_concern.rb', line 31

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

#setup_after_callback(base) ⇒ Object



49
50
51
52
53
# File 'lib/eac_ruby_utils/common_concern.rb', line 49

def setup_after_callback(base)
  common_concern.after_callback.if_present do |v|
    base.instance_eval(&v)
  end
end

#setup_class_methods(base) ⇒ Object



41
42
43
# File 'lib/eac_ruby_utils/common_concern.rb', line 41

def setup_class_methods(base)
  class_methods_module.if_present { |v| base.extend v }
end

#setup_instance_methods(base) ⇒ Object



45
46
47
# File 'lib/eac_ruby_utils/common_concern.rb', line 45

def setup_instance_methods(base)
  instance_methods_module.if_present { |v| base.include v }
end