Class: Cask::CaskLoader::FromPathLoader Private
- Inherits:
-
AbstractContentLoader
- Object
- AbstractContentLoader
- Cask::CaskLoader::FromPathLoader
- Defined in:
- cask/cask_loader.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Loads a cask from a path.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
private
-
#token ⇒ Object
readonly
private
Attributes inherited from AbstractContentLoader
Class Method Summary collapse
-
.can_load?(ref) ⇒ Boolean
private
Instance Method Summary collapse
-
#initialize(path, token: nil) ⇒ FromPathLoader
constructor
private
A new instance of FromPathLoader.
-
#load(config:) ⇒ Object
private
Constructor Details
#initialize(path, token: nil) ⇒ FromPathLoader
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a new instance of FromPathLoader.
91 92 93 94 95 96 97 98 99 100 |
# File 'cask/cask_loader.rb', line 91 def initialize(path, token: nil) super() path = Pathname(path). @token = path.basename(path.extname).to_s @path = path @tap = Homebrew::API.tap_from_source_download(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
89 90 91 |
# File 'cask/cask_loader.rb', line 89 def path @path end |
#token ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
89 90 91 |
# File 'cask/cask_loader.rb', line 89 def token @token end |
Class Method Details
.can_load?(ref) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
84 85 86 87 |
# File 'cask/cask_loader.rb', line 84 def self.can_load?(ref) path = Pathname(ref) %w[.rb .json].include?(path.extname) && path..exist? end |
Instance Method Details
#load(config:) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'cask/cask_loader.rb', line 102 def load(config:) 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 = path.read(encoding: "UTF-8") @config = config if path.extname == ".json" return FromAPILoader.new(token, from_json: JSON.parse(@content)).load(config: config) end begin instance_eval(content, path).tap do |cask| raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask) end rescue NameError, ArgumentError, ScriptError => e error = CaskUnreadableError.new(token, e.) error.set_backtrace e.backtrace raise error end end |