Class: Hbc::CaskLoader::FromContentLoader

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

Direct Known Subclasses

FromPathLoader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ FromContentLoader



18
19
20
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 18

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 4

def content
  @content
end

Class Method Details

.can_load?(ref) ⇒ Boolean



6
7
8
9
10
11
12
13
14
15
16
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 6

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



22
23
24
# File 'Library/Homebrew/cask/lib/hbc/cask_loader.rb', line 22

def load
  instance_eval(content.force_encoding("UTF-8"), __FILE__, __LINE__)
end