forked from rubygarage/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Macro::Decorate
Vladislav Trotsenko edited this page Oct 21, 2020
·
1 revision
Provides to decorate everything from operation context with specified decorator (Draper::Decorator). Supports object or collection as an object for decoration.
class SomeOperation < ApplicationOperation
step :set_decorator # ctx[:decorator] = SomeDecorator
step :set_model # ctx[:model] = SomeEntity.new
step Macro::Decorate() # ctx[:model] = SomeDecorator.decorate(ctx[:model])
endclass SomeOperation < ApplicationOperation
step :set_model # ctx[:model] = SomeEntity.new
step Macro::Decorate(decorator: SomeDecorator) # ctx[:model] = SomeDecorator.decorate(ctx[:model])
endBy default :from and :to are ctx[:model]
class SomeOperation < ApplicationOperation
step :set_collection # ctx[:collection] = Array.new
step Macro::Decorate(decorator: SomeDecorator, from: :collection, to: :other_collection) # ctx[:other_collection] = SomeDecorator.decorate_collection(ctx[:collection])
end