aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/source/uri.rb
blob: 09fab4bd0ebb6a60acbc540e068c72914971ebd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Hbc
  module Source
    class URI
      def self.me?(query)
        !(query.to_s =~ ::URI.regexp).nil?
      end

      attr_reader :uri

      def initialize(uri)
        @uri = uri
      end

      def load
        Hbc.cache.mkpath
        path = Hbc.cache.join(File.basename(uri))
        ohai "Downloading #{uri}"
        odebug "Download target -> #{path}"
        begin
          curl(uri, "-o", path.to_s)
        rescue ErrorDuringExecution
          raise CaskUnavailableError, uri
        end
        PathSlashOptional.new(path).load
      end

      def to_s
        uri.to_s
      end
    end
  end
end