Class: ActiveShopifyGraphQL::LoaderProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shopify_graphql/loader_proxy.rb

Overview

Simple proxy class to handle loader delegation when using a specific API This provides a consistent interface with Relation while using a custom loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class, loader) ⇒ LoaderProxy

Returns a new instance of LoaderProxy.



7
8
9
10
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 7

def initialize(model_class, loader)
  @model_class = model_class
  @loader = loader
end

Instance Attribute Details

#loaderObject (readonly)

Returns the value of attribute loader.



50
51
52
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 50

def loader
  @loader
end

Instance Method Details

#allRelation

Create a Relation with this loader's configuration

Returns:

  • (Relation)

    A relation configured with this loader



14
15
16
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 14

def all
  build_relation
end

#find(id = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 35

def find(id = nil)
  # For Customer Account API, if no ID is provided, load the current customer
  if id.nil? && @loader.is_a?(ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader)
    attributes = @loader.load_attributes
    return nil if attributes.nil?

    return @model_class.new(attributes)
  end

  # For other cases, require ID and use standard flow
  return nil if id.nil?

  build_relation.find(id)
end

#find_by(conditions = {}, **options) ⇒ Object



31
32
33
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 31

def find_by(conditions = {}, **options)
  build_relation.find_by(conditions, **options)
end

#includes(*connection_names) ⇒ Object

Delegate chainable methods to Relation



19
20
21
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 19

def includes(*connection_names)
  build_relation.includes(*connection_names)
end

#inspectObject Also known as: to_s



52
53
54
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 52

def inspect
  "#{@model_class.name}(with_#{@loader.class.name.demodulize})"
end

#select(*attribute_names) ⇒ Object



23
24
25
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 23

def select(*attribute_names)
  build_relation.select(*attribute_names)
end

#where(*args, **options) ⇒ Object



27
28
29
# File 'lib/active_shopify_graphql/loader_proxy.rb', line 27

def where(*args, **options)
  build_relation.where(*args, **options)
end