Class: EPlat::Base

Inherits:
ActiveResource::Base
  • Object
show all
Extended by:
Concerns::OverwriteRequestMethods
Includes:
Concerns::Aliases, Concerns::OverwriteInstanceMethods
Defined in:
lib/e_plat/resource/base.rb

Instance Attribute Summary collapse

Attributes included from Concerns::Aliases

#type_coercer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::OverwriteRequestMethods

create, find, include_root_in_json, instantiate_collection, new

Methods included from Concerns::Aliases

#add_aliases!

Methods included from Concerns::OverwriteInstanceMethods

#include_root_in_json

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

#clientObject

Returns the value of attribute client.



41
42
43
# File 'lib/e_plat/resource/base.rb', line 41

def client
  @client
end

#mapped_attributesObject

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

#mappingObject

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/e_plat/resource/base.rb', line 55

def mapped?(attribute)
  mapped_attributes.include? attribute.to_s
end

#native_keysObject



59
60
61
# File 'lib/e_plat/resource/base.rb', line 59

def native_keys
  (client.shopify?) ? schema.keys : @mapping.native_attributes.presence
end