Class: ShopifyOracle::Accessor::Base
- Inherits:
-
Object
- Object
- ShopifyOracle::Accessor::Base
- Defined in:
- lib/shopify_oracle/accessor/base.rb
Direct Known Subclasses
Customer, SellingPlanGroup, SubscriptionContract, SubscriptionDraft
Instance Attribute Summary collapse
-
#gid ⇒ Object
readonly
Returns the value of attribute gid.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, object_class: Hash) ⇒ Base
constructor
A new instance of Base.
- #reload ⇒ Object
Constructor Details
#initialize(id:, object_class: Hash) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shopify_oracle/accessor/base.rb', line 22 def initialize(id:, object_class: Hash) @oracle = ShopifyOracle class_name = self.class.name.split('::').last object_class_name = class_name.camelize(:lower) @gid = id.is_a?(Integer) ? "gid://shopify/#{class_name}/#{id}" : id object = self.class.find(id: @gid).body['data'][object_class_name] @object = JSON.parse(object.to_json, object_class:) end |
Instance Attribute Details
#gid ⇒ Object (readonly)
Returns the value of attribute gid.
20 21 22 |
# File 'lib/shopify_oracle/accessor/base.rb', line 20 def gid @gid end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
20 21 22 |
# File 'lib/shopify_oracle/accessor/base.rb', line 20 def object @object end |
Class Method Details
.class_name ⇒ Object
15 16 17 |
# File 'lib/shopify_oracle/accessor/base.rb', line 15 def class_name name.split('::').last end |
.find(id:) ⇒ Object
11 12 13 |
# File 'lib/shopify_oracle/accessor/base.rb', line 11 def find(id:) ShopifyOracle.query(class_name.underscore, id:) end |
.list(first: 10) ⇒ Object
7 8 9 |
# File 'lib/shopify_oracle/accessor/base.rb', line 7 def list(first: 10) ShopifyOracle.query(class_name.underscore.pluralize, first:) end |
Instance Method Details
#reload ⇒ Object
34 35 36 37 |
# File 'lib/shopify_oracle/accessor/base.rb', line 34 def reload object = self.class.find(id: @gid).body['data'][object_class] @object = JSON.parse(object.to_json, object_class:) end |