Module: Dekoden::Decoratable
- Defined in:
- lib/dekoden.rb
Class Method Summary collapse
Instance Method Summary collapse
- #decorated_methods ⇒ Object
- #decorated_singleton_methods ⇒ Object
- #decorators(*mojules) ⇒ Object
- #singleton_decorators(*mojules) ⇒ Object
- #unbound_decorators ⇒ Object
Class Method Details
.extended(mojule) ⇒ Object
81 82 83 |
# File 'lib/dekoden.rb', line 81 def self.extended(mojule) mojule.singleton_class.prepend(SingletonPrependMethods) end |
.included(mojule) ⇒ Object
85 86 87 |
# File 'lib/dekoden.rb', line 85 def self.included(mojule) mojule.prepend(SingletonPrependMethods) end |
Instance Method Details
#decorated_methods ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/dekoden.rb', line 63 def decorated_methods unless const_defined?(:DecoratedMethods, false) mojule = Module.new self.prepend(mojule) self.const_set(:DecoratedMethods, mojule) end self.const_get(:DecoratedMethods) end |
#decorated_singleton_methods ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/dekoden.rb', line 72 def decorated_singleton_methods unless const_defined?(:DecoratedSingletonMethods, false) mojule = Module.new self.singleton_class.prepend(mojule) self.const_set(:DecoratedSingletonMethods, mojule) end self.const_get(:DecoratedSingletonMethods) end |
#decorators(*mojules) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dekoden.rb', line 37 def decorators(*mojules) mojules.each do |mojule| mojule.constants.each do |constant| decorator_klass = mojule.const_get(constant) define_singleton_method(constant) do |*args, &blk| unbound_decorators << decorator_klass.new(*args, &blk) end end end end |
#singleton_decorators(*mojules) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dekoden.rb', line 48 def singleton_decorators(*mojules) mojules.each do |mojule| mojule.constants.each do |constant| decorator_klass = mojule.const_get(constant) define_method(constant) do |*args, &blk| unbound_decorators << decorator_klass.new(*args, &blk) end end end end |
#unbound_decorators ⇒ Object
59 60 61 |
# File 'lib/dekoden.rb', line 59 def unbound_decorators @unbound_decorators ||= [] end |