Module: Casting::MissingMethodClient

Defined in:
lib/casting/missing_method_client.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object (private)



54
55
56
57
58
59
60
61
# 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

Instance Method Details

#cast_as(*attendants) ⇒ Object



5
6
7
8
9
10
11
12
# 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) ⇒ Object



22
23
24
25
26
# 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) ⇒ Object



40
41
42
43
44
# 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) ⇒ Object



34
35
36
37
38
# 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) ⇒ Object



28
29
30
31
32
# 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) ⇒ Object



14
15
16
17
18
19
20
# 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