Module: Rack::Mount::Mixover
- Included in:
- Analysis::Frequency, Route, RouteSet
- Defined in:
- lib/rack/mount/mixover.rb
Overview
A mixin that changes the behavior of include
. Instead of modules being chained as a superclass, they are mixed into the objects metaclass. This allows mixins to be stacked ontop of the instance methods.
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
- #extended_modules ⇒ Object
-
#include(*mod) ⇒ Object
Replaces include with a lazy version.
-
#new(*args, &block) ⇒ Object
:nodoc:.
-
#new_with_module(mod, *args, &block) ⇒ Object
Create a new class temporarily with a module.
-
#new_without_module(mod, *args, &block) ⇒ Object
Create a new class without an included module.
Class Method Details
.extended(klass) ⇒ Object
7 8 9 10 11 |
# File 'lib/rack/mount/mixover.rb', line 7 def self.extended(klass) klass.instance_eval do @extended_modules = [] end end |
Instance Method Details
#extended_modules ⇒ Object
27 28 29 |
# File 'lib/rack/mount/mixover.rb', line 27 def extended_modules Thread.current[extended_modules_thread_local_key] || @extended_modules end |
#include(*mod) ⇒ Object
Replaces include with a lazy version.
23 24 25 |
# File 'lib/rack/mount/mixover.rb', line 23 def include(*mod) extended_modules.push(*mod) end |
#new(*args, &block) ⇒ Object
:nodoc:
31 32 33 34 35 36 37 |
# File 'lib/rack/mount/mixover.rb', line 31 def new(*args, &block) #:nodoc: obj = allocate obj.extend(InstanceMethods) extended_modules.each { |mod| obj.extend(mod) } obj.send(:initialize, *args, &block) obj end |
#new_with_module(mod, *args, &block) ⇒ Object
Create a new class temporarily with a module.
48 49 50 51 52 53 |
# File 'lib/rack/mount/mixover.rb', line 48 def new_with_module(mod, *args, &block) (Thread.current[extended_modules_thread_local_key] = extended_modules.dup).push(*mod) new(*args, &block) ensure Thread.current[extended_modules_thread_local_key] = nil end |
#new_without_module(mod, *args, &block) ⇒ Object
Create a new class without an included module.
40 41 42 43 44 45 |
# File 'lib/rack/mount/mixover.rb', line 40 def new_without_module(mod, *args, &block) (Thread.current[extended_modules_thread_local_key] = extended_modules.dup).delete(mod) new(*args, &block) ensure Thread.current[extended_modules_thread_local_key] = nil end |