Class: Cask::CaskLoader::FromContentLoader Private

Inherits:
Object
  • Object
show all
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 string.

Direct Known Subclasses

FromPathLoader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ FromContentLoader

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.

Returns a new instance of FromContentLoader.


30
31
32
# File 'Library/Homebrew/cask/cask_loader.rb', line 30

def initialize(content)
  @content = content.force_encoding("UTF-8")
end

Instance Attribute Details

#contentObject (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.


15
16
17
# File 'Library/Homebrew/cask/cask_loader.rb', line 15

def content
  @content
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.

Returns:

  • (Boolean)

17
18
19
20
21
22
23
24
25
26
27
28
# File 'Library/Homebrew/cask/cask_loader.rb', line 17

def self.can_load?(ref)
  return false unless ref.respond_to?(:to_str)

  content = ref.to_str

  token  = /(?:"[^"]*"|'[^']*')/
  curly  = /\(\s*#{token.source}\s*\)\s*\{.*\}/
  do_end = /\s+#{token.source}\s+do(?:\s*;\s*|\s+).*end/
  regex  = /\A\s*cask(?:#{curly.source}|#{do_end.source})\s*\Z/m

  content.match?(regex)
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.


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

def load(config:)
  @config = config

  instance_eval(content, __FILE__, __LINE__)
end