Skip to content

Commit

Permalink
s/to_api_hash/to_internal_api_hash/
Browse files Browse the repository at this point in the history
  • Loading branch information
apainintheneck committed Mar 8, 2024
1 parent 12d5a40 commit e0cea90
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def to_h
end

# @private
def to_api_hash
def to_internal_api_hash
api_hash = {
"token" => token,

Check warning on line 364 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L364

Added line #L364 was not covered by tests
"name" => name,
Expand Down Expand Up @@ -408,7 +408,7 @@ def to_hash_with_variations(hash_method: :to_h)
if loaded_from_api? && !Homebrew::EnvConfig.no_install_from_api?
return api_to_local_hash(Homebrew::API::Cask.all_casks[token].dup)
end
when :to_api_hash
when :to_internal_api_hash
raise ArgumentError, "API Hash must be generated from Ruby source files" if loaded_from_api?
else
raise ArgumentError, "Unknown hash method #{hash_method.inspect}"
Expand Down Expand Up @@ -440,7 +440,7 @@ def to_hash_with_variations(hash_method: :to_h)
end
end

hash["variations"] = variations if hash_method != :to_api_hash || variations.present?
hash["variations"] = variations if hash_method != :to_internal_api_hash || variations.present?
hash
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/generate-cask-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def generate_cask_api
raise
end

homebrew_cask_tap_json = JSON.generate(tap.to_api_hash)
homebrew_cask_tap_json = JSON.generate(tap.to_internal_api_hash)

Check warning on line 78 in Library/Homebrew/dev-cmd/generate-cask-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-cask-api.rb#L78

Added line #L78 was not covered by tests
File.write("api/internal/v3/homebrew-cask.json", homebrew_cask_tap_json) unless args.dry_run?
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/generate-formula-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generate_formula_api
raise
end

homebrew_core_tap_json = JSON.generate(tap.to_api_hash)
homebrew_core_tap_json = JSON.generate(tap.to_internal_api_hash)

Check warning on line 77 in Library/Homebrew/dev-cmd/generate-formula-api.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/generate-formula-api.rb#L77

Added line #L77 was not covered by tests
File.write("api/internal/v3/homebrew-core.json", homebrew_core_tap_json) unless args.dry_run?
canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table))
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ def to_hash
end

# @private
def to_api_hash
def to_internal_api_hash
api_hash = {
"desc" => desc,
"license" => SPDX.license_expression_to_string(license),
Expand Down Expand Up @@ -2356,14 +2356,14 @@ def to_api_hash

# @private
def to_hash_with_variations(hash_method: :to_hash)
if loaded_from_api? && hash_method == :to_api_hash
if loaded_from_api? && hash_method == :to_internal_api_hash
raise ArgumentError, "API Hash must be generated from Ruby source files"
end

namespace_prefix = case hash_method
when :to_hash
"Variations"
when :to_api_hash
when :to_internal_api_hash
"APIVariations"
else
raise ArgumentError, "Unknown hash method #{hash_method.inspect}"
Expand Down Expand Up @@ -2404,7 +2404,7 @@ def to_hash_with_variations(hash_method: :to_hash)
end
end

hash["variations"] = variations if hash_method != :to_api_hash || variations.present?
hash["variations"] = variations if hash_method != :to_internal_api_hash || variations.present?
hash
end

Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,10 @@ def formula_files_by_name
end

sig { returns(T::Hash[String, T.untyped]) }
def to_api_hash
def to_internal_api_hash
formulae_api_hash = formula_names.to_h do |name|
formula = Formulary.factory(name)
formula_hash = formula.to_hash_with_variations(hash_method: :to_api_hash)
formula_hash = formula.to_hash_with_variations(hash_method: :to_internal_api_hash)
[name, formula_hash]
end

Expand Down Expand Up @@ -1372,10 +1372,10 @@ def tap_migrations
end

sig { returns(T::Hash[String, T.untyped]) }
def to_api_hash
def to_internal_api_hash
casks_api_hash = cask_tokens.to_h do |token|
cask = Cask::CaskLoader.load(token)
cask_hash = cask.to_hash_with_variations(hash_method: :to_api_hash)
cask_hash = cask.to_hash_with_variations(hash_method: :to_internal_api_hash)
[token, cask_hash]

Check warning on line 1379 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L1376-L1379

Added lines #L1376 - L1379 were not covered by tests
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it "creates the expected hash" do
api_hash = CoreTap.instance.to_api_hash
api_hash = CoreTap.instance.to_internal_api_hash
api_hash["tap_git_head"] = tap_git_head # tricky to mock

expect(JSON.pretty_generate(api_hash)).to eq(internal_tap_json)
Expand Down

0 comments on commit e0cea90

Please sign in to comment.