Sha256: 8901484f9985b2d972b6d0ede2cd9d64fe7409b6313c9a5f00d3c8fc10b02814

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'berkeley_library/util'

module BerkeleyLibrary
  module Location
    module HathiTrust
      module Config
        include BerkeleyLibrary::Util::URIs

        ENV_HATHITRUST_BASE_URL = 'LIT_HATHITRUST_BASE_URL'.freeze

        # The default HathiTrust base URL, if ENV_HATHITRUST_BASE_URL is not set.
        DEFAULT_HATHITRUST_BASE_URL = 'https://catalog.hathitrust.org/api/'.freeze

        class << self
          include Config
        end

        def base_uri
          @base_uri ||= default_hathitrust_base_uri
        end

        def base_uri=(value)
          @base_uri = uri_or_nil(value)
        end

        private

        def reset!
          remove_instance_variable(:@base_uri) if instance_variable_defined?(:@base_uri)
        end

        def default_hathitrust_base_uri
          uri_or_nil(default_hathitrust_base_url)
        end

        def default_hathitrust_base_url
          ENV[ENV_HATHITRUST_BASE_URL] || rails_hathitrust_base_url || DEFAULT_HATHITRUST_BASE_URL
        end

        def rails_hathitrust_base_url
          return unless (rails_config = self.rails_config)
          return unless rails_config.respond_to?(:hathitrust_base_url)

          rails_config.hathitrust_base_url
        end

        def rails_config
          return unless defined?(Rails)
          return unless (app = Rails.application)

          app.config
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
berkeley_library-location-4.1.0 lib/berkeley_library/location/hathi_trust/config.rb
berkeley_library-location-4.0.0 lib/berkeley_library/location/hathi_trust/config.rb
berkeley_library-location-3.0.0 lib/berkeley_library/location/hathi_trust/config.rb
berkeley_library-location-2.0.0 lib/berkeley_library/location/hathi_trust/config.rb