Module: Aws::Templates::Utils::Inheritable::ClassMethods

Included in:
Aws::Templates::Utils::Inheritable
Defined in:
lib/aws/templates/utils/inheritable.rb

Overview

Core class-level mixins

Contains core logic of the inheritance feature. This module is used as extention in every including module/class to expose appropriate module-level primitives for handling inheritance of class-scope methods.

Constant Summary collapse

DEFAULT_MODULE =
Module.new.freeze

Instance Method Summary collapse

Instance Method Details

#_merge_class_scope(mod) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/aws/templates/utils/inheritable.rb', line 37

def _merge_class_scope(mod)
  if @class_scope.nil?
    @class_scope = mod.dup
  else
    @class_scope.include(mod)
  end

  extend @class_scope
end

#class_scope(&blk) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/aws/templates/utils/inheritable.rb', line 28

def class_scope(&blk)
  if blk
    @class_scope.module_eval(&blk)
    extend @class_scope
  end

  @class_scope
end

#included(base) ⇒ Object

To add class methods also while including the module



18
19
20
21
22
# File 'lib/aws/templates/utils/inheritable.rb', line 18

def included(base)
  super(base)
  base.extend(Inheritable::ClassMethods)
  base._merge_class_scope(class_scope || DEFAULT_MODULE)
end

#instance_scope(&blk) ⇒ Object



24
25
26
# File 'lib/aws/templates/utils/inheritable.rb', line 24

def instance_scope(&blk)
  module_eval(&blk)
end