Skip to content

Commit

Permalink
tap: add constants for json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylan12 committed Nov 9, 2020
1 parent b4d4f6d commit 4ae72e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 1 addition & 7 deletions Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1190,14 +1190,8 @@ def audit
audit_tap_audit_exceptions
end

HOMEBREW_TAP_JSON_FILES = %w[
formula_renames.json
tap_migrations.json
audit_exceptions/*.json
].freeze

def audit_json_files
json_patterns = HOMEBREW_TAP_JSON_FILES.map { |pattern| @path/pattern }
json_patterns = Tap::HOMEBREW_TAP_JSON_FILES.map { |pattern| @path/pattern }
Pathname.glob(json_patterns).each do |file|
JSON.parse file.read
rescue JSON::ParserError
Expand Down
16 changes: 13 additions & 3 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class Tap

TAP_DIRECTORY = (HOMEBREW_LIBRARY/"Taps").freeze

HOMEBREW_TAP_FORMULA_RENAMES_FILE = "formula_renames.json"
HOMEBREW_TAP_MIGRATIONS_FILE = "tap_migrations.json"
HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR = "audit_exceptions"

HOMEBREW_TAP_JSON_FILES = %W[
#{HOMEBREW_TAP_FORMULA_RENAMES_FILE}
#{HOMEBREW_TAP_MIGRATIONS_FILE}
#{HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR}/*.json
].freeze

def self.fetch(*args)
case args.length
when 1
Expand Down Expand Up @@ -526,7 +536,7 @@ def to_hash

# Hash with tap formula renames
def formula_renames
@formula_renames ||= if (rename_file = path/"formula_renames.json").file?
@formula_renames ||= if (rename_file = path/HOMEBREW_TAP_FORMULA_RENAMES_FILE).file?
JSON.parse(rename_file.read)
else
{}
Expand All @@ -535,7 +545,7 @@ def formula_renames

# Hash with tap migrations
def tap_migrations
@tap_migrations ||= if (migration_file = path/"tap_migrations.json").file?
@tap_migrations ||= if (migration_file = path/HOMEBREW_TAP_MIGRATIONS_FILE).file?
JSON.parse(migration_file.read)
else
{}
Expand All @@ -546,7 +556,7 @@ def tap_migrations
def audit_exceptions
@audit_exceptions = {}

Pathname.glob(path/"audit_exceptions/*").each do |exception_file|
Pathname.glob(path/HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR/"*").each do |exception_file|
list_name = exception_file.basename.to_s.chomp(".json").to_sym
list_contents = begin
JSON.parse exception_file.read
Expand Down

0 comments on commit 4ae72e0

Please sign in to comment.