Class: Casting::PreparedDelegation
- Inherits:
-
Object
- Object
- Casting::PreparedDelegation
- Defined in:
- lib/casting/prepared_delegation.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#attendant ⇒ Object
Returns the value of attribute attendant.
-
#block ⇒ Object
writeonly
Sets the attribute block.
-
#client ⇒ Object
Returns the value of attribute client.
-
#delegated_method_name ⇒ Object
Returns the value of attribute delegated_method_name.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(**settings, &block) ⇒ PreparedDelegation
constructor
A new instance of PreparedDelegation.
- #to(object_or_module) ⇒ Object
- #with(*args, &block) ⇒ Object
Constructor Details
#initialize(**settings, &block) ⇒ PreparedDelegation
Returns a new instance of PreparedDelegation.
16 17 18 19 20 21 22 |
# File 'lib/casting/prepared_delegation.rb', line 16 def initialize(**settings, &block) @delegated_method_name = settings[:delegated_method_name] @client = settings[:client] @attendant = settings[:attendant] @arguments = settings[:arguments] @block = block end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
13 14 15 |
# File 'lib/casting/prepared_delegation.rb', line 13 def arguments @arguments end |
#attendant ⇒ Object
Returns the value of attribute attendant.
13 14 15 |
# File 'lib/casting/prepared_delegation.rb', line 13 def attendant @attendant end |
#block=(value) ⇒ Object
Sets the attribute block
13 14 15 |
# File 'lib/casting/prepared_delegation.rb', line 13 def block=(value) @block = value end |
#client ⇒ Object
Returns the value of attribute client.
13 14 15 |
# File 'lib/casting/prepared_delegation.rb', line 13 def client @client end |
#delegated_method_name ⇒ Object
Returns the value of attribute delegated_method_name.
13 14 15 |
# File 'lib/casting/prepared_delegation.rb', line 13 def delegated_method_name @delegated_method_name 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 |