Class: Rails::GraphQL::Helpers::AttributeDelegator

Inherits:
BasicObject
Defined in:
lib/rails/graphql/helpers/attribute_delegator.rb

Overview

This is an extra magic on top of the delegator class from the standard lib that allows fetching a specific property of the delegated object

Direct Known Subclasses

Request::Strategy::DynamicInstance

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, attribute = nil, cache: true, &block) ⇒ AttributeDelegator

Returns a new instance of AttributeDelegator.



12
13
14
15
16
# File 'lib/rails/graphql/helpers/attribute_delegator.rb', line 12

def initialize(obj = nil, attribute = nil, cache: true, &block)
  @delegate_sd_attr = attribute
  @delegate_sd_obj = block.presence || obj
  @delegate_cache = cache
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **xargs, &block) ⇒ Object (private)



28
29
30
31
# File 'lib/rails/graphql/helpers/attribute_delegator.rb', line 28

def method_missing(method_name, *args, **xargs, &block)
  return super unless __getobj__.respond_to?(method_name)
  __getobj__.public_send(method_name, *args, **xargs, &block)
end

Instance Method Details

#raise(*args) ⇒ Object



18
19
20
# File 'lib/rails/graphql/helpers/attribute_delegator.rb', line 18

def raise(*args)
  ::Object.send(:raise, *args)
end