module DuckPuncher
Constants
- VERSION
Attributes
log[RW]
log=[RW]
logger[RW]
Public Class Methods
call(*args)
click to toggle source
# File lib/duck_puncher.rb, line 37 def call(*args) options = args.last.is_a?(Hash) ? args.pop : {} classes = args.any? ? args : Ducks.list.keys classes.each do |klass| klass = lookup_constant(klass) Ducks[klass].sort.each do |duck| duck.punch_options = Ducks::Object.instance_method(:clone!).bind(options).call duck.punch_options[:target] ||= klass if punched_ducks.include?(duck) logger.warn %(Already punched #{duck.mod.name}) elsif duck.punch(duck.punch_options).any? punched_ducks << duck else logger.warn %(No punches were thrown) end end end nil end
Also aliased as: punch_all!, punch!
deregister(*)
click to toggle source
Calls superclass method
# File lib/duck_puncher.rb, line 79 def deregister(*) super @cached_decorators = nil end
punched_ducks()
click to toggle source
# File lib/duck_puncher.rb, line 61 def punched_ducks @punched_ducks ||= Set.new end
register(*)
click to toggle source
Register an extension with a target class When given a block, the block is used to create an anonymous module @param target [Class,Module,Object] constant or instance to extend @param mods [Array<Module>] modules to extend or mix into the target. The last argument can be a hash of options to customize the extension @option :only [Symbol, Array<Symbol>] list of methods to extend onto the target (the module must have these defined) @option :method [Symbol,String] the method used to apply the module, e.g. :extend (:include) @option :before [Proc] A hook that is called with the target class before punch @option :after [Proc] A hook that is called with the target class after punch
Calls superclass method
# File lib/duck_puncher.rb, line 73 def register(*) target, *_ = super decorators[target] = build_decorator_class(*Ducks[target]) @cached_decorators = nil end