Module: Servizio::Service::MethodDecorators

Included in:
Servizio::Service
Defined in:
lib/servizio/service.rb

Overview

This code does some metaprogramming magic. It overwrites .new, so that every instance of a class derived from Servizio::Service, gets a module prepended automatically. This way, one can easily “wrap” the methods, e.g. #call.

Defined Under Namespace

Modules: Call

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/servizio/service.rb', line 88

def inherited(subclass)
  subclass.instance_eval do
    alias :original_new :new

    def self.inherited(subsubclass)
      subsubclass.extend(Servizio::Service::MethodDecorators)
    end

    def self.new(*args, &block)
      (obj = original_new(*args, &block)).singleton_class.send(:prepend, Servizio::Service::MethodDecorators::Call)
      return obj
    end
  end
end