Sha256: 66a5a92033b8e07f1aa36349c8e5925b13d31d92b0f90e29adfc400916badb4a

Contents?: true

Size: 827 Bytes

Versions: 2

Compression:

Stored size: 827 Bytes

Contents

module DuckPuncher
  # @note When updating this file please update comment regarding this module in duck_puncher.rb
  module Registration
    def register(target, *mods)
      options = mods.last.is_a?(Hash) ? mods.pop : {}
      target = DuckPuncher.lookup_constant target
      Ducks.list[target] = Set.new [] unless Ducks.list.key?(target)
      Array(mods).each do |mod|
        duck = Duck.new target, mod, options
        Ducks.list[target] << duck
        decorators[target] = build_decorator_class(duck, *Ducks[target])
      end
      @cached_decorators = nil
    end

    def register!(*args)
      register *args
      call args.first
    end

    def deregister(*classes)
      classes.each &Ducks.list.method(:delete)
      classes.each &decorators.method(:delete)
      @cached_decorators = nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
duck_puncher-4.2.3 lib/duck_puncher/registration.rb
duck_puncher-4.2.2 lib/duck_puncher/registration.rb