30 lines
532 B
Ruby
Raw Normal View History

2016-08-18 22:11:42 +03:00
require "rubygems"
2016-10-08 13:25:38 +02:00
require "hbc/cask_loader"
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
module Hbc
module Source
class PathBase
# derived classes must define method self.me?
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.path_for_query(query)
2016-10-08 13:25:38 +02:00
Pathname.new(query).sub(%r{(\.rb)?$}, ".rb")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
attr_reader :path
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def initialize(path)
2016-10-08 13:25:38 +02:00
@path = Pathname.new(path).expand_path
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def load
2016-10-08 13:25:38 +02:00
CaskLoader.load_from_file(@path)
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def to_s
# stringify to fully-resolved location
2016-10-08 13:25:38 +02:00
@path.to_s
2016-09-24 13:52:43 +02:00
end
end
2016-08-18 22:11:42 +03:00
end
end