From ea2e40c69a112741243556637c5c6493751c73e2 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sat, 14 Aug 2021 16:18:13 -0400 Subject: [PATCH] Add `Cask::Cask#source` to return cask's source code --- Library/Homebrew/cask/cask.rb | 5 +++-- Library/Homebrew/cask/cask_loader.rb | 2 +- Library/Homebrew/cask/installer.rb | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 20bff3b592..35c7e3b4a0 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -20,7 +20,7 @@ module Cask extend Searchable include Metadata - attr_reader :token, :sourcefile_path, :config, :default_config + attr_reader :token, :sourcefile_path, :source, :config, :default_config def self.each(&block) return to_enum unless block @@ -38,9 +38,10 @@ module Cask @tap end - def initialize(token, sourcefile_path: nil, tap: nil, config: nil, &block) + def initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil, &block) @token = token @sourcefile_path = sourcefile_path + @source = source @tap = tap @block = block diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index fa7eed16ae..0b231fcbc9 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -40,7 +40,7 @@ module Cask private def cask(header_token, **options, &block) - Cask.new(header_token, **options, config: @config, &block) + Cask.new(header_token, source: content, **options, config: @config, &block) end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index ec1a004058..9377f89958 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -399,10 +399,10 @@ module Cask def save_caskfile old_savedir = @cask.metadata_timestamped_path - return unless @cask.sourcefile_path + return if @cask.source.blank? savedir = @cask.metadata_subdir("Casks", timestamp: :now, create: true) - FileUtils.copy @cask.sourcefile_path, savedir + (savedir/"#{@cask.token}.rb").write @cask.source old_savedir&.rmtree end