Sha256: cd8faed562fc8932b4698492a9a5de2825869c74a98d36211ceaa3db9c9d412c

Contents?: true

Size: 902 Bytes

Versions: 3

Compression:

Stored size: 902 Bytes

Contents

module GhostInThePost
  module JSLoaders
    module NetworkLoader
      extend self

      def load(url)
        uri = uri_for_url(url)
        Net::HTTP.get(uri) if uri
      end

      def uri_for_url(url)
        uri = URI(url)

        if uri.host.present?
          return uri if uri.scheme.present?
          URI("http://#{uri.to_s}")
        elsif asset_host_present?
          scheme, host = asset_host.split(%r{:?//})
          scheme, host = host, scheme if host.nil?
          scheme = 'http' if scheme.blank?
          path = url
          URI(File.join("#{scheme}://#{host}", path))
        end
      end

      def asset_host_present?
        ::Rails.configuration.action_controller.asset_host.present?
      end

      def asset_host
        config = ::Rails.configuration.action_controller.asset_host
        config.respond_to?(:call) ? config.call : config
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ghost_in_the_post-0.1.4 lib/ghost_in_the_post/js_loaders/network_loader.rb
ghost_in_the_post-0.1.3 lib/ghost_in_the_post/js_loaders/network_loader.rb
ghost_in_the_post-0.1.2 lib/ghost_in_the_post/js_loaders/network_loader.rb