class KDecor::BaseDecorator

Base decorator

Attributes

compatible_type[RW]

Compatible type will store the Object Type that this decorator is suitable for processing

implemented_behaviours[RW]

What are the specific behaviours available on this decorator

If you wish to use a decorator to run against a compatible data type you do not need individual behaviours then set implemented_behaviours to [:default]

But if this decorator type only targets certain behaviours then give it a list of specific :behaviour to perform. e.g. [:update_fields, :update_rows]

Public Class Methods

new(compatible_type) click to toggle source
# File lib/k_decor/base_decorator.rb, line 22
def initialize(compatible_type)
  @compatible_type = compatible_type
  @implemented_behaviours = []
end

Public Instance Methods

behaviour?(behaviour) click to toggle source

Does the decorator implement the behaviour , any = false)

# File lib/k_decor/base_decorator.rb, line 29
def behaviour?(behaviour)
  behaviour == :all || implemented_behaviours.include?(behaviour)
end
compatible?(target) click to toggle source
# File lib/k_decor/base_decorator.rb, line 33
def compatible?(target)
  target.is_a?(compatible_type)
end
decorate(target, **opts) click to toggle source
# File lib/k_decor/base_decorator.rb, line 37
def decorate(target, **opts)
  raise KType::Error, "#{self.class} is incompatible with data object" unless compatible?(target)
  raise KType::Error, "#{self.class} has not implemented an update method" unless respond_to?(:update)

  update(target, **opts)
end