module Light::Decorator::Concerns::Base

Public Instance Methods

==(other) click to toggle source
Calls superclass method
# File lib/light/decorator/concerns/base.rb, line 28
def ==(other)
  super || other.respond_to?(:object) && self == other.object
end
decorate(options = {}) click to toggle source

Decorate ActiveRecord::Model

@param [Hash] options (optional) @return [Object] decorator or self

# File lib/light/decorator/concerns/base.rb, line 11
def decorate(options = {})
  return self if decorated?

  klass = decorator_class(options)
  klass.decorate(self, options)
rescue Light::Decorator::NotFound => e
  raise e unless options[:soft]
  self
end
decorated?() click to toggle source

Check current ActiveRecord::Model is decorated or not

@return [Bool]

# File lib/light/decorator/concerns/base.rb, line 24
def decorated?
  false
end
eql?(other) click to toggle source
Calls superclass method
# File lib/light/decorator/concerns/base.rb, line 32
def eql?(other)
  super || other.respond_to?(:object) && eql?(other.object)
end

Private Instance Methods

decorator_class(options) click to toggle source
# File lib/light/decorator/concerns/base.rb, line 38
def decorator_class(options)
  with = options.delete(:with)
  return "#{self.class}Decorator".constantize unless with

  with = with.constantize unless with.is_a?(Class)
  with
rescue NameError
  raise Light::Decorator::NotFound, "Decorator#{with ? " #{with}" : ''} for #{self.class} not found"
end