Skip to content
Vladislav Trotsenko edited this page Apr 10, 2020 · 1 revision

Synopsis

Provides to decorate everything from operation context with specified decorator (Draper::Decorator). Supports object or collection as an object for decoration.

Examples of usage

Decorate model with preseted decorator

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])
end

Decorate model with directly passed decorator

class SomeOperation < ApplicationOperation
  step :set_model # ctx[:model] = SomeEntity.new
  step Macro::Decorate(decorator: SomeDecorator) # ctx[:model] = SomeDecorator.decorate(ctx[:model])
end

Decorate from somewhere to somewhere with directly passed decorator or not

By 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
Clone this wiki locally