aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/source/path_base.rb
blob: 4e4bdcf158ddaedc7ff6c9d74acd011b9060c3cb (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
require "rubygems"
require "hbc/cask_loader"

module Hbc
  module Source
    class PathBase
      # derived classes must define method self.me?

      def self.path_for_query(query)
        Pathname.new(query).sub(/(\.rb)?$/, ".rb")
      end

      attr_reader :path

      def initialize(path)
        @path = Pathname.new(path).expand_path
      end

      def load
        CaskLoader.load_from_file(@path)
      end

      def to_s
        # stringify to fully-resolved location
        @path.to_s
      end
    end
  end
end