Class: Cask::CaskLoader::FromContentLoader Private

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

Instance Attribute Summary

Attributes inherited from AbstractContentLoader

#content, #tap

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, tap: T.unsafe(nil)) ⇒ void

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.

Parameters:

  • content (String)
  • tap (Tap) (defaults to: T.unsafe(nil))


70
71
72
73
74
75
# File 'cask/cask_loader.rb', line 70

def initialize(content, tap: T.unsafe(nil))
  super()

  @content = content.dup.force_encoding("UTF-8")
  @tap = tap
end

Class Method Details

.try_new(ref, warn: false) ⇒ 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.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'cask/cask_loader.rb', line 51

def self.try_new(ref, warn: false)
  return false unless ref.respond_to?(:to_str)

  content = T.unsafe(ref).to_str

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

  return unless content.match?(@regex)

  new(content)
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.



77
78
79
80
81
# File 'cask/cask_loader.rb', line 77

def load(config:)
  @config = config

  instance_eval(content, __FILE__, __LINE__)
end