Class: AmazonSchema
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AmazonSchema
- Includes:
- Models::Auditable
- Defined in:
- app/models/amazon_schema.rb
Overview
== Schema Information
Table name: amazon_schemas
Database name: primary
id :bigint not null, primary key
amazon_channel :enum not null
locale :string not null
product_type :string not null
schema :jsonb not null
created_at :datetime not null
updated_at :datetime not null
amazon_marketplace_id :integer not null
Indexes
index_amazon_schemas_on_amazon_marketplace_id (amazon_marketplace_id)
Foreign Keys
fk_rails_... (amazon_marketplace_id => amazon_marketplaces.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #product_type ⇒ String readonly
- #schema ⇒ Hash readonly
Belongs to collapse
Methods included from Models::Auditable
Delegated Instance Attributes collapse
-
#keys ⇒ Object
Alias for Properties#keys.
Class Method Summary collapse
Instance Method Summary collapse
- #orchestrator ⇒ Edi::Amazon::Orchestrator
- #properties ⇒ Hash
- #property_definition(property_name) ⇒ Hash?
- #refresh_schema ⇒ void
- #schema_as_json ⇒ String?
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#product_type ⇒ String (readonly)
33 |
# File 'app/models/amazon_schema.rb', line 33 validates :product_type, presence: true |
#schema ⇒ Hash (readonly)
35 |
# File 'app/models/amazon_schema.rb', line 35 validates :schema, presence: true |
Class Method Details
.valid_locales ⇒ Array<String>
96 97 98 |
# File 'app/models/amazon_schema.rb', line 96 def self.valid_locales Edi::Amazon::Orchestrator.orchestrators.flat_map(&:locales).uniq end |
Instance Method Details
#amazon_marketplace ⇒ AmazonMarketplace
31 |
# File 'app/models/amazon_schema.rb', line 31 belongs_to :amazon_marketplace, inverse_of: :amazon_schemas |
#keys ⇒ Object
Alias for Properties#keys
45 |
# File 'app/models/amazon_schema.rb', line 45 delegate :keys, to: :properties |
#orchestrator ⇒ Edi::Amazon::Orchestrator
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/amazon_schema.rb', line 66 def orchestrator raise "Not implemented yet Amazon Channel: #{amazon_channel}" unless amazon_channel_seller? case amazon_marketplace.country.iso when 'US' Edi::Amazon::Orchestrator.new(:amazon_seller_central_us) when 'CA' Edi::Amazon::Orchestrator.new(:amazon_seller_central_ca) when 'DE' Edi::Amazon::Orchestrator.new(:amazon_seller_central_de) when 'FR' Edi::Amazon::Orchestrator.new(:amazon_seller_central_fr) when 'ES' Edi::Amazon::Orchestrator.new(:amazon_seller_central_es) when 'IT' Edi::Amazon::Orchestrator.new(:amazon_seller_central_it) when 'NL' Edi::Amazon::Orchestrator.new(:amazon_seller_central_nl) when 'BE' Edi::Amazon::Orchestrator.new(:amazon_seller_central_be) when 'PL' Edi::Amazon::Orchestrator.new(:amazon_seller_central_pl) when 'SE' Edi::Amazon::Orchestrator.new(:amazon_seller_central_se) else raise "Not implemented yet Marketplace ID: #{amazon_marketplace_id}" end end |
#properties ⇒ Hash
41 42 43 |
# File 'app/models/amazon_schema.rb', line 41 def properties schema.fetch('properties', {}).symbolize_keys end |
#property_definition(property_name) ⇒ Hash?
49 50 51 |
# File 'app/models/amazon_schema.rb', line 49 def property_definition(property_name) properties[property_name.to_sym] end |
#refresh_schema ⇒ void
This method returns an undefined value.
61 62 63 |
# File 'app/models/amazon_schema.rb', line 61 def refresh_schema orchestrator.pull_schema_for_locale(product_type, locale, amazon_schema: self) end |
#schema_as_json ⇒ String?
54 55 56 57 58 |
# File 'app/models/amazon_schema.rb', line 54 def schema_as_json return if schema.blank? JSON.pretty_generate(JSON.parse(schema.to_json)) end |