Class: TinyDecorator::SingleDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- TinyDecorator::SingleDecorator
- Extended by:
- Delegatable
- Defined in:
- lib/tiny_decorator/single_decorator.rb
Overview
Single decorator. Inherite, then define methods to use. This base decorator delegates all. To limit delegation to source object.
“‘ class NewDecorator < TinyDecorator::SingleDecorator
def new_method
'decorated'
end
end
NewDecorator.decorate(Object.new).new_method # ‘decorated’ NewDecorator.decorate_collection([Object.new, Object.new]).new_method # ‘decorated’ “‘
Use in case source has only 1 decorator. In case more than 1 decorator or conditional decorate, we prefer using TinyDecorator::CompositeDecorator
Constant Summary
Constants included from Delegatable
Delegatable::DELEGATION_RESERVED_KEYWORDS, Delegatable::DELEGATION_RESERVED_METHOD_NAMES, Delegatable::RUBY_RESERVED_KEYWORDS
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#preloaded ⇒ Object
readonly
Returns the value of attribute preloaded.
Class Method Summary collapse
-
.decorate_collection(delegatees, context = {}) ⇒ Object
Decorate a collection, collection must extend Enum behavior.
Instance Method Summary collapse
-
#initialize(delegatee, context = {}, preloaded = {}) ⇒ SingleDecorator
constructor
Initialize, use
.decorateor.neware the same.
Methods included from Delegatable
Constructor Details
#initialize(delegatee, context = {}, preloaded = {}) ⇒ SingleDecorator
Initialize, use .decorate or .new are the same
24 25 26 27 28 |
# File 'lib/tiny_decorator/single_decorator.rb', line 24 def initialize(delegatee, context = {}, preloaded = {}) @context = context @preloaded = preloaded __setobj__(delegatee) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
29 30 31 |
# File 'lib/tiny_decorator/single_decorator.rb', line 29 def context @context end |
#preloaded ⇒ Object (readonly)
Returns the value of attribute preloaded.
29 30 31 |
# File 'lib/tiny_decorator/single_decorator.rb', line 29 def preloaded @preloaded end |
Class Method Details
.decorate_collection(delegatees, context = {}) ⇒ Object
Decorate a collection, collection must extend Enum behavior
35 36 37 38 39 |
# File 'lib/tiny_decorator/single_decorator.rb', line 35 def decorate_collection(delegatees, context = {}) delegatees.map do |delegatee| new(delegatee, context) end end |