Class: Cask::CaskLoader::FromPathLoader Private
- Inherits:
-
FromContentLoader
- Object
- FromContentLoader
- Cask::CaskLoader::FromPathLoader
- Defined in:
- Library/Homebrew/cask/cask_loader.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Loads a cask from a path.
Direct Known Subclasses
Instance Attribute Summary collapse
- #path ⇒ Object readonly private
- #token ⇒ Object readonly private
Attributes inherited from FromContentLoader
Class Method Summary collapse
- .can_load?(ref) ⇒ Boolean private
Instance Method Summary collapse
-
#initialize(path) ⇒ FromPathLoader
constructor
private
rubocop:disable Lint/MissingSuper.
- #load(config:) ⇒ Object private
Constructor Details
#initialize(path) ⇒ FromPathLoader
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Lint/MissingSuper
56 57 58 59 60 61 |
# File 'Library/Homebrew/cask/cask_loader.rb', line 56 def initialize(path) # rubocop:disable Lint/MissingSuper path = Pathname(path). @token = path.basename(".rb").to_s @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'Library/Homebrew/cask/cask_loader.rb', line 54 def path @path end |
#token ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'Library/Homebrew/cask/cask_loader.rb', line 54 def token @token end |
Class Method Details
.can_load?(ref) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 |
# File 'Library/Homebrew/cask/cask_loader.rb', line 49 def self.can_load?(ref) path = Pathname(ref) path.extname == ".rb" && path..exist? end |
Instance Method Details
#load(config:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'Library/Homebrew/cask/cask_loader.rb', line 63 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 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 |