Class: EacRubyUtils::CommonConcern::ClassSetup

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

Constant Summary

Constants included from SimpleCache

SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, SimpleCache::UNCACHED_METHOD_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleCache

#method_missing, #reset_cache, #respond_to_missing?, uncached_method_name

Constructor Details

#initialize(module_setup, a_class, include_method) ⇒ ClassSetup

Returns a new instance of ClassSetup.



13
14
15
16
17
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 13

def initialize(module_setup, a_class, include_method)
  @module_setup = module_setup
  @a_class = a_class
  @include_method = include_method
end

Dynamic Method Handling

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

Instance Attribute Details

#a_classObject (readonly)

Returns the value of attribute a_class.



11
12
13
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 11

def a_class
  @a_class
end

#include_methodObject (readonly)

Returns the value of attribute include_method.



11
12
13
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 11

def include_method
  @include_method
end

#module_setupObject (readonly)

Returns the value of attribute module_setup.



11
12
13
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 11

def module_setup
  @module_setup
end

Instance Method Details

#class_methods_module_uncachedObject



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

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

#instance_methods_module_uncachedObject



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

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

#runObject



19
20
21
22
23
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 19

def run
  %w[class_methods instance_methods after_callback].each do |suffix|
    send("setup_#{suffix}")
  end
end

#setup_after_callbackObject



33
34
35
36
37
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 33

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

#setup_class_methodsObject



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

def setup_class_methods
  class_methods_module.if_present { |v| a_class.extend v }
end

#setup_instance_methodsObject



29
30
31
# File 'lib/eac_ruby_utils/common_concern/class_setup.rb', line 29

def setup_instance_methods
  instance_methods_module.if_present { |v| a_class.send(include_method, v) }
end