Module: RuGUI::InitializeHooks

Included in:
BaseController, BaseModel, BaseView, BaseViewHelper
Defined in:
lib/rugui/initialize_hooks.rb

Overview

Adds before/after hooks for initialize method of a class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/rugui/initialize_hooks.rb', line 4

def self.included(base)
  self.update_initialize_method(base)
end

.update_initialize_method(base) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rugui/initialize_hooks.rb', line 8

def self.update_initialize_method(base)
  base.class_eval <<-class_eval
    alias :original_initialize :initialize

    def initialize(*args)
      initialize_with_hooks(*args)
    end
  class_eval
end

Instance Method Details

#initialize_with_hooks(*args) ⇒ Object

Calls the original initialize method with before/after hooks.



19
20
21
22
23
# File 'lib/rugui/initialize_hooks.rb', line 19

def initialize_with_hooks(*args)
  before_initialize
  original_initialize(*args)
  after_initialize
end