Class: Homebrew::FormulaTextAuditor Private

Inherits:
Object
  • Object
show all
Defined in:
formula_text_auditor.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.

Auditor for checking common violations in Formula text content.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FormulaTextAuditor

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.

Returns a new instance of FormulaTextAuditor.



9
10
11
12
# File 'formula_text_auditor.rb', line 9

def initialize(path)
  @text = path.open("rb", &:read)
  @lines = @text.lines.to_a
end

Instance Method Details

#=~(other) ⇒ 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.



22
23
24
# File 'formula_text_auditor.rb', line 22

def =~(other)
  other =~ @text
end

#include?(s) ⇒ Boolean

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.

Returns:

  • (Boolean)


26
27
28
# File 'formula_text_auditor.rb', line 26

def include?(s)
  @text.include? s
end

#line_number(regex, skip = 0) ⇒ 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.



30
31
32
33
# File 'formula_text_auditor.rb', line 30

def line_number(regex, skip = 0)
  index = @lines.drop(skip).index { |line| line =~ regex }
  index ? index + 1 : nil
end

#reverse_line_number(regex) ⇒ 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.



35
36
37
38
# File 'formula_text_auditor.rb', line 35

def reverse_line_number(regex)
  index = @lines.reverse.index { |line| line =~ regex }
  index ? @lines.count - index : nil
end

#trailing_newline?Boolean

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.

Returns:

  • (Boolean)


18
19
20
# File 'formula_text_auditor.rb', line 18

def trailing_newline?
  /\Z\n/ =~ @text
end

#without_patchObject

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.



14
15
16
# File 'formula_text_auditor.rb', line 14

def without_patch
  @text.split("\n__END__").first
end