module Casting::Client
Public Class Methods
extended(base)
click to toggle source
# File lib/casting/client.rb, line 17 def self.extended(base) unless base.respond_to?(:delegate) add_delegate_method_to(base.singleton_class) end end
included(base)
click to toggle source
# File lib/casting/client.rb, line 7 def self.included(base) def base.delegate_missing_methods(*which) Casting::Client.set_delegation_strategy(self, *which.reverse) end unless base.method_defined?(:delegate) add_delegate_method_to(base) end end
Private Class Methods
add_delegate_method_to(base)
click to toggle source
# File lib/casting/client.rb, line 53 def self.add_delegate_method_to(base) base.class_eval { alias_method :delegate, :cast } end
set_delegation_strategy(base, *which)
click to toggle source
# File lib/casting/client.rb, line 44 def self.set_delegation_strategy(base, *which) which = [:instance] if which.empty? which.map! { |selection| selection == :instance && selection = method(:set_method_missing_client) selection == :class && selection = method(:set_method_missing_client_class) selection }.map { |meth| meth.call(base) } end
set_method_missing_client(base)
click to toggle source
# File lib/casting/client.rb, line 57 def self.set_method_missing_client(base) base.send(:include, ::Casting::MissingMethodClient) end
set_method_missing_client_class(base)
click to toggle source
# File lib/casting/client.rb, line 61 def self.set_method_missing_client_class(base) base.send(:extend, ::Casting::MissingMethodClientClass) end
Public Instance Methods
cast(delegated_method_name, attendant, ...)
click to toggle source
# File lib/casting/client.rb, line 27 def cast(delegated_method_name, attendant, ...) validate_attendant(attendant) delegation(delegated_method_name).to(attendant).call(...) end
delegate_missing_methods(*which)
click to toggle source
# File lib/casting/client.rb, line 32 def delegate_missing_methods(*which) Casting::Client.set_delegation_strategy(singleton_class, *which.reverse) end
delegation(delegated_method_name)
click to toggle source
# File lib/casting/client.rb, line 23 def delegation(delegated_method_name) Casting::Delegation.prepare(delegated_method_name, self) end
Private Instance Methods
validate_attendant(attendant)
click to toggle source
# File lib/casting/client.rb, line 38 def validate_attendant(attendant) if attendant == self raise Casting::InvalidAttendant.new("client can not delegate to itself") end end