Class: Hbc::CaskLoader::FromPathLoader

Inherits:
FromContentLoader show all
Defined in:
Library/Homebrew/cask/lib/hbc/cask_loader.rb

Direct Known Subclasses

FromTapPathLoader, FromURILoader, NullLoader

Instance Attribute Summary collapse

Attributes inherited from FromContentLoader

#content

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FromPathLoader

Returns a new instance of FromPathLoader



41
42
43
44
45
46
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 41

def initialize(path)
  path = Pathname(path).expand_path

  @token = path.basename(".rb").to_s
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path



39
40
41
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 39

def path
  @path
end

#tokenObject (readonly)

Returns the value of attribute token



39
40
41
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 39

def token
  @token
end

Class Method Details

.can_load?(ref) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 34

def self.can_load?(ref)
  path = Pathname(ref)
  path.extname == ".rb" && path.expand_path.exist?
end

Instance Method Details

#loadObject



48
49
50
51
52
53
54
55
56
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 48

def load
  raise CaskUnavailableError.new(token, "'#{path}' does not exist.")  unless path.exist?
  raise CaskUnavailableError.new(token, "'#{path}' is not readable.") unless path.readable?
  raise CaskUnavailableError.new(token, "'#{path}' is not a file.")   unless path.file?

  @content = IO.read(path)

  super
end