Add Cask::Cask#source to return cask's source code

This commit is contained in:
Rylan Polster 2021-08-14 16:18:13 -04:00
parent 99635bf3ae
commit ea2e40c69a
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
3 changed files with 6 additions and 5 deletions

View File

@ -20,7 +20,7 @@ module Cask
extend Searchable extend Searchable
include Metadata include Metadata
attr_reader :token, :sourcefile_path, :config, :default_config attr_reader :token, :sourcefile_path, :source, :config, :default_config
def self.each(&block) def self.each(&block)
return to_enum unless block return to_enum unless block
@ -38,9 +38,10 @@ module Cask
@tap @tap
end 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 @token = token
@sourcefile_path = sourcefile_path @sourcefile_path = sourcefile_path
@source = source
@tap = tap @tap = tap
@block = block @block = block

View File

@ -40,7 +40,7 @@ module Cask
private private
def cask(header_token, **options, &block) 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
end end

View File

@ -399,10 +399,10 @@ module Cask
def save_caskfile def save_caskfile
old_savedir = @cask.metadata_timestamped_path 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) 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 old_savedir&.rmtree
end end