Class: Magic::Decorator::Base

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Lookup
Includes:
Magic::Decoratable
Defined in:
lib/magic/decorator/base.rb

Direct Known Subclasses

EnumerableDecorator

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Magic::Decoratable

#decorate, #decorate!, #decorated

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/magic/decorator/base.rb', line 39

def method_missing(method, ...)
  return super if method.start_with? 'to_' # converter
  return super if method.start_with? '_'   # system

  if block_given?
    super { |*args| yield *args.map(&:decorated) }
  else
    super
  end.decorated
rescue NoMethodError => error
  __raise__ error.class.new(
      error.message.sub(self.class.name, __getobj__.class.name),
      error.name,
      error.args,
  #    error.private_call?, # FIXME: not implemented in TruffleRuby

      receiver: __getobj__
  ).tap {
    _1.set_backtrace error.backtrace[2..] # FIXME: use `backtrace_locations` with Ruby 3.4+
  }
end

Class Method Details

.name_for(object_class) ⇒ Object



12
# File 'lib/magic/decorator/base.rb', line 12

def name_for(object_class) = "#{object_class}Decorator"

Instance Method Details

#decorated?Boolean

Returns:

  • (Boolean)


30
# File 'lib/magic/decorator/base.rb', line 30

def decorated? = true