class Draper::Factory::Worker

@private

def call(options)

def call(options)
  update_context options
  decorator.call(object, options)
end

def collection?

def collection?
  object.respond_to?(:first) && !object.is_a?(Struct)
end

def decoratable?

def decoratable?
  object.respond_to?(:decorate)
end

def decorator

def decorator
  return decorator_method(decorator_class) if decorator_class
  return object_decorator if decoratable?
  return decorator_method(Draper::CollectionDecorator) if collection?
  raise Draper::UninferrableDecoratorError.new(object.class)
end

def decorator_method(klass)

def decorator_method(klass)
  if collection? && klass.respond_to?(:decorate_collection)
    klass.method(:decorate_collection)
  else
    klass.method(:decorate)
  end
end

def initialize(decorator_class, object)

def initialize(decorator_class, object)
  @decorator_class = decorator_class
  @object = object
end

def object_decorator

def object_decorator
  if collection?
    ->(object, options) { object.decorator_class.decorate_collection(object, options.reverse_merge(with: nil))}
  else
    ->(object, options) { object.decorate(options) }
  end
end

def update_context(options)

def update_context(options)
  args = options.delete(:context_args)
  options[:context] = options[:context].call(*Array.wrap(args)) if options[:context].respond_to?(:call)
end