module Decoru::Decoratable

Public Instance Methods

decorate() click to toggle source

Decorate collection with appropriate decorator

# File lib/decoru/decoratable.rb, line 7
def decorate
  all.map(&:decorate)
end
Also aliased as: decoru
decorated?() click to toggle source
# File lib/decoru/decoratable.rb, line 34
def decorated?
  false
end
decorator_class(called_on = self) click to toggle source

Infers the decorator class to be used by (e.g. `User` maps to `UserDecorator`). adapted from github.com/drapergem/draper/blob/157eb955072a941e6455e0121fca09a989fcbc21/lib/draper/decoratable.rb#L71

# File lib/decoru/decoratable.rb, line 15
def decorator_class(called_on = self)
  prefix = respond_to?(:model_name) ? model_name : name
  decorator_name = "#{prefix}Decorator"
  decorator_name_constant = decorator_name.safe_constantize
  return decorator_name_constant unless decorator_name_constant.nil?

  return superclass.decorator_class(called_on) if superclass.respond_to?(:decorator_class)

  raise Decoru::UninferrableDecoratorError, "Could not infer a decorator for #{called_on.name}."
end
decoru()
Alias for: decorate