Class: Serega::AttributeValueResolvers::DelegateAllowNil
- Inherits:
-
Object
- Object
- Serega::AttributeValueResolvers::DelegateAllowNil
- Defined in:
- lib/serega/attribute_value_resolvers/delegate.rb
Overview
Value resolver class for attributes with :delegate (with :allow_nil) option
Instance Method Summary collapse
-
#call(object) ⇒ Object?
Delegates method call to another object with safe navigation.
-
#initialize(delegate_to, method_name) ⇒ DelegateAllowNil
constructor
A new instance of DelegateAllowNil.
Constructor Details
#initialize(delegate_to, method_name) ⇒ DelegateAllowNil
29 30 31 32 |
# File 'lib/serega/attribute_value_resolvers/delegate.rb', line 29 def initialize(delegate_to, method_name) @delegate_to = delegate_to @method_name = method_name end |
Instance Method Details
#call(object) ⇒ Object?
Delegates method call to another object with safe navigation
40 41 42 |
# File 'lib/serega/attribute_value_resolvers/delegate.rb', line 40 def call(object) object.public_send(delegate_to)&.public_send(method_name) end |