Module: DuckPuncher
- Extended by:
- AncestralHash, Decoration, Registration, Utilities
- Defined in:
- lib/duck_puncher.rb,
lib/duck_puncher/duck.rb,
lib/duck_puncher/ducks.rb,
lib/duck_puncher/version.rb,
lib/duck_puncher/utilities.rb,
lib/duck_puncher/decoration.rb,
lib/duck_puncher/ducks/hash.rb,
lib/duck_puncher/unique_duck.rb,
lib/duck_puncher/ducks/method.rb,
lib/duck_puncher/ducks/module.rb,
lib/duck_puncher/ducks/object.rb,
lib/duck_puncher/ducks/string.rb,
lib/duck_puncher/json_storage.rb,
lib/duck_puncher/registration.rb,
lib/duck_puncher/ducks/numeric.rb,
lib/duck_puncher/ancestral_hash.rb,
lib/duck_puncher/ducks/enumerable.rb,
lib/duck_puncher/ducks/active_record.rb
Defined Under Namespace
Modules: AncestralHash, Decoration, Ducks, JSONStorage, Registration, Utilities Classes: Duck, GemInstaller, UniqueDuck
Constant Summary collapse
- VERSION =
'5.0.0'.freeze
Class Attribute Summary collapse
-
.logger ⇒ Object
(also: log)
Returns the value of attribute logger.
Class Method Summary collapse
- .call(*args) ⇒ Object (also: punch_all!, punch!)
- .deregister ⇒ Object
- .punched_ducks ⇒ Object
-
.register ⇒ Object
Register an extension with a target class When given a block, the block is used to create an anonymous module.
Methods included from AncestralHash
Methods included from Utilities
lookup_constant, redefine_constant
Methods included from Decoration
build_decorator_class, cached_decorators, decorate, decorators, undecorate
Methods included from Registration
deregister, register, register!
Class Attribute Details
.logger ⇒ Object Also known as: log
Returns the value of attribute logger.
31 32 33 |
# File 'lib/duck_puncher.rb', line 31 def logger @logger end |
Class Method Details
.call(*args) ⇒ Object Also known as: punch_all!, punch!
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/duck_puncher.rb', line 37 def call(*args) = 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. = Ducks::Object.instance_method(:clone!).bind().call duck.[:target] ||= klass if punched_ducks.include?(duck) logger.warn %(Already punched #{duck.mod.name}) elsif duck.punch(duck.).any? punched_ducks << duck else logger.warn %(No punches were thrown) end end end nil end |
.deregister ⇒ Object
79 80 81 82 |
# File 'lib/duck_puncher.rb', line 79 def deregister(*) super @cached_decorators = nil end |
.punched_ducks ⇒ Object
61 62 63 |
# File 'lib/duck_puncher.rb', line 61 def punched_ducks @punched_ducks ||= Set.new end |
.register ⇒ Object
Register an extension with a target class When given a block, the block is used to create an anonymous module
73 74 75 76 77 |
# File 'lib/duck_puncher.rb', line 73 def register(*) target, *_ = super decorators[target] = build_decorator_class(*Ducks[target]) @cached_decorators = nil end |