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)

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

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::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#nameString?

Returns Carrier display name.

Returns:

  • (String, nil)

    Carrier display name.



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

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:



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

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

.lookupActiveRecord::Relation<Carrier>

A relation of Carriers that are lookup. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Carrier>)

See Also:



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

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

.ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>

Ransack scopes exposed to search.

Parameters:

  • _auth_object (Object) (defaults to: nil)

    unused Ransack auth object

Returns:

  • (Array<Symbol>)


50
51
52
# File 'app/models/carrier.rb', line 50

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:



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

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

Instance Method Details

#supplierParty

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:



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

belongs_to :supplier, optional: true