Class: ActiveShopifyGraphQL::LoaderProxy
- Inherits:
-
Object
- Object
- ActiveShopifyGraphQL::LoaderProxy
- 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
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Instance Method Summary collapse
-
#all ⇒ Relation
Create a Relation with this loader's configuration.
- #find(id = nil) ⇒ Object
- #find_by(conditions = {}, **options) ⇒ Object
-
#includes(*connection_names) ⇒ Object
Delegate chainable methods to Relation.
-
#initialize(model_class, loader) ⇒ LoaderProxy
constructor
A new instance of LoaderProxy.
- #inspect ⇒ Object (also: #to_s)
- #select(*attribute_names) ⇒ Object
- #where(*args, **options) ⇒ Object
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
#loader ⇒ Object (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
#all ⇒ Relation
Create a Relation with this loader's configuration
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 = {}, **) build_relation.find_by(conditions, **) 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 |
#inspect ⇒ Object 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, **) build_relation.where(*args, **) end |