Class: Casting::PreparedDelegation

Inherits:
Object
  • Object
show all
Defined in:
lib/casting/prepared_delegation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ PreparedDelegation

Returns a new instance of PreparedDelegation.



17
18
19
20
21
22
# File 'lib/casting/prepared_delegation.rb', line 17

def initialize(settings)
  @delegated_method_name = settings[:delegated_method_name]
  @client = settings[:client]
  @attendant = settings[:attendant]
  @arguments = settings[:arguments]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/casting/prepared_delegation.rb', line 13

def client
  @client
end

Instance Method Details

#call(*args) ⇒ Object

Raises:



40
41
42
43
44
45
46
47
48
49
# File 'lib/casting/prepared_delegation.rb', line 40

def call(*args)
  @arguments = args unless args.empty?
  raise MissingAttendant.new unless attendant

  if arguments
    delegated_method.bind(client).call(*arguments, &block)
  else
    delegated_method.bind(client).call
  end
end

#to(object_or_module) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/casting/prepared_delegation.rb', line 24

def to(object_or_module)
  @attendant = object_or_module
  begin
    check_valid_type
  rescue TypeError
    @attendant = method_module || raise
  end
  self
end

#with(*args, &block) ⇒ Object



34
35
36
37
38
# File 'lib/casting/prepared_delegation.rb', line 34

def with(*args, &block)
  @arguments = args
  @block = block
  self
end