Class: EPlat::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- EPlat::Base
- Extended by:
- Concerns::OverwriteRequestMethods
- Defined in:
- lib/e_plat/resource/base.rb
Direct Known Subclasses
Order, Order::Customer, Order::Fulfillment, Order::LineItem, Order::ShippingLine, Product, Product::Image, Product::Option, Product::Variant, Shop
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#mapped_attributes ⇒ Object
Returns the value of attribute mapped_attributes.
-
#mapping ⇒ Object
Returns the value of attribute mapping.
Attributes included from Concerns::Aliases
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}, persisted = false) ⇒ Base
constructor
A new instance of Base.
- #mapped?(attribute) ⇒ Boolean
- #native_keys ⇒ Object
Methods included from Concerns::OverwriteRequestMethods
create, find, include_root_in_json, instantiate_collection, new
Methods included from Concerns::Aliases
Methods included from Concerns::OverwriteInstanceMethods
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Base
Returns a new instance of Base.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/e_plat/resource/base.rb', line 43 def initialize(attributes = {}, persisted = false) self.client = Current.e_plat_session site = client.base_url self.mapping = mapping_instance ActiveResource::Base.include_root_in_json = client.shopify? && top_level_resource? super add_aliases!(mapping.native_attribute_aliases, schema) @mapped_attributes = AttributeInterface.new(self, keys: mappable_keys) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
41 42 43 |
# File 'lib/e_plat/resource/base.rb', line 41 def client @client end |
#mapped_attributes ⇒ Object
Returns the value of attribute mapped_attributes.
41 42 43 |
# File 'lib/e_plat/resource/base.rb', line 41 def mapped_attributes @mapped_attributes end |
#mapping ⇒ Object
Returns the value of attribute mapping.
41 42 43 |
# File 'lib/e_plat/resource/base.rb', line 41 def mapping @mapping end |
Class Method Details
.find_by(title:) ⇒ Object
23 24 25 |
# File 'lib/e_plat/resource/base.rb', line 23 def find_by(title:) find(:all, params: { title: title })&.first end |
.initialize_singleton! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/e_plat/resource/base.rb', line 10 def initialize_singleton! self.client = Current.e_plat_session self.site = client.base_url self.prefix = client.url_prefix self.timeout = 5 self.include_format_in_path = !client.bigcommerce? self.mapping = mapping_instance client.platform_headers.each {|name, value| self.headers[name] = value} end |
Instance Method Details
#mapped?(attribute) ⇒ Boolean
55 56 57 |
# File 'lib/e_plat/resource/base.rb', line 55 def mapped?(attribute) mapped_attributes.include? attribute.to_s end |
#native_keys ⇒ Object
59 60 61 |
# File 'lib/e_plat/resource/base.rb', line 59 def native_keys (client.shopify?) ? schema.keys : @mapping.native_attributes.presence end |