Module: FlexCoerce::ModuleMethods

Included in:
FlexCoerce
Defined in:
lib/y_support/flex_coerce/module_methods.rb

Overview

This module contains methods with which FlexProxy and modules which include it are to be extended.

Instance Method Summary collapse

Instance Method Details

#customize_class(host_class) ⇒ Object

This method customizes the host class in which FlexCoerce is included by setting up a parametrized subclass of FlexCoerce::FlexProxy and extending the host class with FlexCoerce::ClassMethods.



11
12
13
14
15
16
17
18
# File 'lib/y_support/flex_coerce/module_methods.rb', line 11

def customize_class host_class
  host_class.instance_exec do
    # Set up a parametrized subclass of FlexCoerce::FlexProxy
    param_class!( { FlexProxy: FlexCoerce::FlexProxy },
                  with: { host_class: host_class } )
  end
  host_class.extend FlexCoerce::ClassMethods
end

#customize_module(host_module) ⇒ Object

This method customizes a module in which FlexCoerce is included by extending it with FlexCoerce::ModuleMethods.



23
24
25
# File 'lib/y_support/flex_coerce/module_methods.rb', line 23

def customize_module host_module
  host_module.extend FlexCoerce::ModuleMethods
end

#included(receiver) ⇒ Object

Hook method which is invoked whenever a module is included in another module (or class, which is also a module).



30
31
32
33
34
35
36
# File 'lib/y_support/flex_coerce/module_methods.rb', line 30

def included receiver
  if receiver.is_a? Class then # we have reached the host class
    customize_class( receiver )
  else # receiver is a Module
    customize_module( receiver )
  end
end