Class: Casting::PreparedDelegation
- Inherits:
-
Object
- Object
- Casting::PreparedDelegation
- Defined in:
- lib/casting/prepared_delegation.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(settings) ⇒ PreparedDelegation
constructor
A new instance of PreparedDelegation.
- #to(object_or_module) ⇒ Object
- #with(*args, &block) ⇒ Object
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
#client ⇒ Object (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
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 |