Class: EacRubyUtils::CommonConstructor::ClassInitialize

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/common_constructor/class_initialize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(common_constructor, klass) ⇒ ClassInitialize

Returns a new instance of ClassInitialize.



11
12
13
14
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 11

def initialize(common_constructor, klass)
  @common_constructor = common_constructor
  @klass = klass
end

Instance Attribute Details

#common_constructorObject (readonly)

Returns the value of attribute common_constructor.



9
10
11
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 9

def common_constructor
  @common_constructor
end

#klassObject (readonly)

Returns the value of attribute klass.



9
10
11
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 9

def klass
  @klass
end

Instance Method Details

#define_initialize_callbacksObject



16
17
18
19
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 16

def define_initialize_callbacks
  klass.include(::ActiveSupport::Callbacks)
  klass.define_callbacks :initialize
end

#define_initialize_methodObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 21

def define_initialize_method
  class_initialize = self
  klass.send(:define_method, :initialize) do |*args, &block|
    ::EacRubyUtils::CommonConstructor::InstanceInitialize.new(
      class_initialize.common_constructor, args, self, block
    ).perform
    super(*::EacRubyUtils::CommonConstructor::SuperArgs.new(
      class_initialize, args, self
    ).result)
  end
end

#performObject



33
34
35
36
# File 'lib/eac_ruby_utils/common_constructor/class_initialize.rb', line 33

def perform
  define_initialize_callbacks
  define_initialize_method
end