class Contracts::Decorator

Attributes

decorators[RW]

Public Class Methods

inherited(klass) click to toggle source
# File lib/contracts/decorators.rb, line 26
    def self.inherited(klass)
      name = klass.name.gsub(/^./) { |m| m.downcase }

      return if name =~ /^[^A-Za-z_]/ || name =~ /[^0-9A-Za-z_]/

      # the file and line parameters set the text for error messages
      # make a new method that is the name of your decorator.
      # that method accepts random args and a block.
      # inside, `decorate` is called with those params.
      MethodDecorators.module_eval "        def #{klass}(*args, &blk)
          ::Contracts::Engine.fetch_from(self).decorate(#{klass}, *args, &blk)
        end
", __FILE__, __LINE__ + 1
    end
new(klass, method) click to toggle source
# File lib/contracts/decorators.rb, line 42
def initialize(klass, method)
  @method = method
end