Module: Decorations

Defined in:
lib/decorations.rb,
lib/decorations/version.rb

Overview

Decorations class to extend within your class

Constant Summary collapse

VERSION =

The version of the Ruby-decorations gem

'1.1.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(receiver) ⇒ Void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Injects the decorated_methods attribute in the class received

Parameters:

  • receiver (Class)

    the class extending Decorations

Returns:

  • (Void)


17
18
19
20
21
# File 'lib/decorations.rb', line 17

def self.extended(receiver)
  class << receiver
    attr_accessor :decorated_methods
  end
end

Instance Method Details

#decorate(klass, *args, &block) ⇒ Void

Decorates a method execute’s the klass’ #call method around the decorated method

Examples:

class DecoratorDemo < Decorator
  def call(this, chain, *args)
    puts "'#{decorated_class}' has '#{decorated_method.name}' decorated"
    call_next(this, chain, *args)
  end
end

class Demo
  extend Decorations

  decorate DecoratorDemo
  def demo_method
    puts 'am I decorated?'
  end
end

demo = Demo.new
demo.demo_method
# => 'Demo' has 'demo_method' decorated
# => am I decorated?

Returns:

  • (Void)


51
52
53
54
# File 'lib/decorations.rb', line 51

def decorate(klass, *args, &block)
  @decorators ||= []
  @decorators << { klass: klass, args: args, block: block }
end