Class: Carrier

Inherits:
ApplicationRecord show all
Defined in:
app/models/carrier.rb

Overview

== Schema Information

Table name: carriers
Database name: primary

id :bigint not null, primary key
common :boolean default(FALSE), not null
countries_iso :string default([]), is an Array
full_name :string
name :string
scac :string
created_at :datetime not null
updated_at :datetime not null
supplier_id :integer

Indexes

index_carriers_on_countries_iso (countries_iso) USING gin
index_carriers_on_full_name (full_name) USING gin
index_carriers_on_name (name) USING gin
index_carriers_on_scac (scac) UNIQUE
index_carriers_on_supplier_id (supplier_id)

Foreign Keys

fk_rails_... (supplier_id => parties.id)

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#nameObject (readonly)



36
# File 'app/models/carrier.rb', line 36

validates :name, presence: true

Class Method Details

.for_countryActiveRecord::Relation<Carrier>

A relation of Carriers that are for country. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Carrier>)

See Also:



39
# File 'app/models/carrier.rb', line 39

scope :for_country, ->(country_iso) { where.any(country_iso: country_iso) }

.lookupActiveRecord::Relation<Carrier>

A relation of Carriers that are lookup. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Carrier>)

See Also:



40
# File 'app/models/carrier.rb', line 40

scope :lookup, -> (q) { where(Carrier[:scac].matches("%#{q}%").or( Carrier[:name].matches("%#{q}%") ).or( Carrier[:full_name].matches("%#{q}%") ) )}

.ransackable_scopes(_auth_object = nil) ⇒ Object



42
43
44
# File 'app/models/carrier.rb', line 42

def self.ransackable_scopes(_auth_object=nil)
  %i[lookup for_country]
end

.with_scac_codeActiveRecord::Relation<Carrier>

A relation of Carriers that are with scac code. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Carrier>)

See Also:



38
# File 'app/models/carrier.rb', line 38

scope :with_scac_code, -> { where.not(scac: nil) }

Instance Method Details

#supplierSupplier

scac code being a US specific code we don't want to enforce it if we deal
with european or other carriers that do not have one

Returns:

See Also:



31
# File 'app/models/carrier.rb', line 31

belongs_to :supplier, optional: true