Sha256: 4734776278573f3fc8712a7fafb5a2dbe28b24d2cbe5615bf79a1bc781181264

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module FreightKit
  class Platform < Carrier
    # Credentials should be a `Credential` or `Array` of `Credential`
    def initialize(credentials, customer_location: nil, tariff: nil)
      super

      # Use #superclass instead of using #ancestors to fetch the parent class which the carrier class is inheriting from
      # (#ancestors returns an array including the parent class and all the modules that were included)
      parent_class_name = self.class.superclass.name.demodulize.underscore

      conf_path = File
                  .join(
                    File.expand_path(
                      '../../../../configuration/platforms',
                      self.class.const_source_location(:REACTIVE_FREIGHT_PLATFORM).first,
                    ),
                    "#{parent_class_name}.yml",
                  )
      @conf = YAML.safe_load_file(conf_path, permitted_classes: [Symbol])

      conf_path = File
                  .join(
                    File.expand_path(
                      '../../../../configuration/carriers',
                      self.class.const_source_location(:REACTIVE_FREIGHT_CARRIER).first,
                    ),
                    "#{self.class.to_s.demodulize.underscore}.yml",
                  )
      @conf = @conf.deep_merge(YAML.safe_load_file(conf_path, permitted_classes: [Symbol]))

      @rates_with_excessive_length_fees = @conf.dig(:attributes, :rates, :with_excessive_length_fees)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
freight_kit-0.1.11 lib/freight_kit/platform.rb
freight_kit-0.1.10 lib/freight_kit/platform.rb
freight_kit-0.1.7 lib/freight_kit/platform.rb