module Casting::MissingMethodClient

Public Instance Methods

cast_as(*attendants) click to toggle source
# File lib/casting/missing_method_client.rb, line 5
def cast_as(*attendants)
  attendants.each do |attendant|
    validate_attendant(attendant)
    attendant.cast_object(self) if attendant.respond_to?(:cast_object)
    __delegates__.unshift(attendant)
  end
  self
end
delegated_methods(all = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 22
def delegated_methods(all = true)
  __delegates__.flat_map { |attendant|
    attendant_methods(attendant, all)
  }
end
delegated_private_methods(include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 40
def delegated_private_methods(include_super = true)
  __delegates__.flat_map { |attendant|
    attendant_private_methods(attendant, include_super)
  }
end
delegated_protected_methods(include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 34
def delegated_protected_methods(include_super = true)
  __delegates__.flat_map { |attendant|
    attendant_protected_methods(attendant, include_super)
  }
end
delegated_public_methods(include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 28
def delegated_public_methods(include_super = true)
  __delegates__.flat_map { |attendant|
    attendant_public_methods(attendant, include_super)
  }
end
uncast(count = 1) click to toggle source
# File lib/casting/missing_method_client.rb, line 14
def uncast(count = 1)
  count.times do
    attendant = __delegates__.shift
    attendant.uncast_object(self) if attendant.respond_to?(:uncast_object)
  end
  self
end

Private Instance Methods

__delegates__() click to toggle source
# File lib/casting/missing_method_client.rb, line 48
def __delegates__
  Thread.current[:instance_delegates] ||= {}
  Thread.current[:instance_delegates][object_id] ||= []
  Thread.current[:instance_delegates][object_id]
end
attendant_methods(attendant, all = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 74
def attendant_methods(attendant, all = true)
  collection = attendant_public_methods(attendant) + attendant_protected_methods(attendant)
  collection += attendant_private_methods(attendant) if all
  collection
end
attendant_private_methods(attendant, include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 96
def attendant_private_methods(attendant, include_super = true)
  if Module === attendant
    attendant.private_instance_methods(include_super)
  else
    attendant.private_methods(include_super)
  end
end
attendant_protected_methods(attendant, include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 88
def attendant_protected_methods(attendant, include_super = true)
  if Module === attendant
    attendant.protected_instance_methods(include_super)
  else
    attendant.protected_methods(include_super)
  end
end
attendant_public_methods(attendant, include_super = true) click to toggle source
# File lib/casting/missing_method_client.rb, line 80
def attendant_public_methods(attendant, include_super = true)
  if Module === attendant
    attendant.public_instance_methods(include_super)
  else
    attendant.public_methods(include_super)
  end
end
method_delegate(meth) click to toggle source
# File lib/casting/missing_method_client.rb, line 67
def method_delegate(meth)
  __delegates__.find { |attendant|
    attendant.respond_to?(:method_defined?) && attendant.method_defined?(meth) ||
      attendant_methods(attendant).include?(meth)
  }
end
method_missing(meth, ...) click to toggle source
Calls superclass method
# File lib/casting/missing_method_client.rb, line 54
def method_missing(meth, ...)
  attendant = method_delegate(meth)
  if !!attendant
    cast(meth, attendant, ...)
  else
    super
  end
end
respond_to_missing?(meth, *) click to toggle source
Calls superclass method
# File lib/casting/missing_method_client.rb, line 63
def respond_to_missing?(meth, *)
  !!method_delegate(meth) || super
end