Class: Cask::CaskLoader::FromContentLoader

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/cask/cask_loader.rb

Direct Known Subclasses

FromPathLoader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ FromContentLoader

Returns a new instance of FromContentLoader



24
25
26
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 24

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content



9
10
11
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 9

def content
  @content
end

Class Method Details

.can_load?(ref) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 11

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

  content = ref.to_str

  token  = /(?:"[^"]*"|'[^']*')/
  curly  = /\(\s*#{token}\s*\)\s*\{.*\}/
  do_end = /\s+#{token}\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

#loadObject



28
29
30
# File 'brew/Library/Homebrew/cask/cask_loader.rb', line 28

def load
  instance_eval(content, __FILE__, __LINE__)
end