Class: EPlat::Base
Direct Known Subclasses
Metafield, Order, Order::Consignment, Order::Fulfillment, Order::LineItem, Order::ShippingAddress, Order::ShippingLine, Product, Product::Image, Product::Option, Product::Variant, Product::Variant::OptionValue, RecurringApplicationCharge, RecurringApplicationCharge::UsageCharge, ScriptTag, Shop, Webhook
Constant Summary
Concerns::GraphQLable::FILTER_ARGS, Concerns::GraphQLable::QUERY_ARG_ARGS
Class Attribute Summary collapse
Instance Attribute Summary collapse
#type_coercer
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Countable
count
#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from
#add_aliases!
#as_full_json, #to_full_json
#collection_path, #element_path, included
#as_eplat_json, #as_json, #create, #create_resource_for, #to_eplat_json, #to_json, #update
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Base
Returns a new instance of Base.
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/e_plat/resource/base.rb', line 93
def initialize(attributes = {}, persisted = false)
site = client.base_url
ActiveResource::Base.include_root_in_json = client.shopify? && top_level_resource?
super
self.mapping = mapping_instance
@mapped_attributes = ensure_e_plat_attributes!
ensure_native_attributes!
add_aliases!(mapping.native_attribute_aliases, type_schema || {})
end
|
Class Attribute Details
.read_only ⇒ Object
Returns the value of attribute read_only.
18
19
20
|
# File 'lib/e_plat/resource/base.rb', line 18
def read_only
@read_only
end
|
Instance Attribute Details
#mapped_attributes ⇒ Object
Returns the value of attribute mapped_attributes.
91
92
93
|
# File 'lib/e_plat/resource/base.rb', line 91
def mapped_attributes
@mapped_attributes
end
|
#mapping ⇒ Object
Returns the value of attribute mapping.
91
92
93
|
# File 'lib/e_plat/resource/base.rb', line 91
def mapping
@mapping
end
|
Class Method Details
.cached_shopify_webhook? ⇒ Boolean
75
76
77
|
# File 'lib/e_plat/resource/base.rb', line 75
def cached_shopify_webhook?
self.to_s.include?("EPlat::ShopifyWebhook")
end
|
.exclude_from_json(read_only) ⇒ Object
67
68
69
|
# File 'lib/e_plat/resource/base.rb', line 67
def exclude_from_json(read_only)
self.read_only = read_only
end
|
.inherited(subclass) ⇒ Object
23
24
25
26
27
|
# File 'lib/e_plat/resource/base.rb', line 23
def inherited(subclass)
super
subclass.exclude_from_json(read_only) if read_only
subclass.schema ||= schema.dup
end
|
.initialize_singleton! ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/e_plat/resource/base.rb', line 29
def initialize_singleton!
self.site = client.base_url self.prefix = client.url_prefix(klass: self)
self.timeout = 5
self.include_format_in_path = client.include_format_in_path?
self.mapping = mapping_instance
client..each {|name, value| self.[name] = value}
end
|
71
72
73
|
# File 'lib/e_plat/resource/base.rb', line 71
def platform_specific_class?
self.class.to_s.include? client.platform.to_s.capitalize
end
|
.prefix=(value = "/") ⇒ Object
monkey patch prefix= so we can add thread-local value to the generated prefix_source() method
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/e_plat/resource/base.rb', line 46
def prefix=(value = "/")
prefix_call = value.gsub(/:\w+/) { |key| "\#{URI::DEFAULT_PARSER.escape options[#{key}].to_s}" }
@prefix_parameters = nil
silence_warnings do
instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def prefix_source()
client.url_prefix(klass: self) || "#{value}"
end
def prefix(options={}) "#{prefix_call}" end
RUBY_EVAL
end
rescue Exception => e
logger.error "Couldn't set prefix: #{e}\n #{code}" if logger
raise
end
|
Instance Method Details
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/e_plat/resource/base.rb', line 139
def formatted_id
return id unless client.shopify? && client.api_version != "2024_01"
return if id.to_s.include?("gid://")
case element_name
when "product"
"gid://shopify/Product/#{id}"
when "variant"
"gid://shopify/ProductVariant/#{id}"
when "image"
"gid://shopify/ProductImage/#{id}"
else
id
end
end
|
155
156
157
|
# File 'lib/e_plat/resource/base.rb', line 155
def graphql_input
raise EPlat::Error.new("GraphQL input not supported for this resource and platform")
end
|
129
130
131
|
# File 'lib/e_plat/resource/base.rb', line 129
def
full_response&.&.to_h || {}
end
|
#include_root_in_json ⇒ Object
133
134
135
136
137
|
# File 'lib/e_plat/resource/base.rb', line 133
def include_root_in_json
return false unless client.shopify?
top_level_resource?
end
|
#mapped?(attribute) ⇒ Boolean
111
112
113
|
# File 'lib/e_plat/resource/base.rb', line 111
def mapped?(attribute)
mapped_attributes.include? attribute.to_s
end
|
#native_keys ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/e_plat/resource/base.rb', line 115
def native_keys
if client.shopify?
@mapping.native_attributes.presence || schema.keys elsif mapping.class.to_s != EPlat::Mapping::Base && @mapping.native_attributes.present?
@mapping.native_attributes.presence
else
attributes.keys
end
end
|
#read_only? ⇒ Boolean
125
126
127
|
# File 'lib/e_plat/resource/base.rb', line 125
def read_only?
!!self.class.read_only
end
|