From 87f29857f0d5a8c862ed90b1740e192d5312c0db Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Wed, 23 Oct 2019 18:34:16 +0300 Subject: [PATCH] Pass section to the constructor --- Library/Homebrew/cask/artifact/manpage.rb | 18 +++++++++--------- .../test/cask/artifact/manpage_spec.rb | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/artifact/manpage.rb b/Library/Homebrew/cask/artifact/manpage.rb index 6938f6035d..9f6f57aebd 100644 --- a/Library/Homebrew/cask/artifact/manpage.rb +++ b/Library/Homebrew/cask/artifact/manpage.rb @@ -5,26 +5,26 @@ require "cask/artifact/symlinked" module Cask module Artifact class Manpage < Symlinked + attr_reader :section + def self.from_args(cask, source) - section = source.split(".").last + section = source.to_s[/\.([1-8]|n|l)$/, 1] - raise CaskInvalidError, "section should be a positive number" unless section.to_i.positive? + raise CaskInvalidError, "'#{source}' is not a valid man page name" unless section - new(cask, source) + new(cask, source, section) end - def initialize(cask, source) - super + def initialize(cask, source, section) + @section = section + + super(cask, source) end def resolve_target(_target) config.manpagedir.join("man#{section}", target_name) end - def section - @source.extname.downcase[1..-1].to_s.to_i - end - def target_name "#{@source.basename(@source.extname)}.#{section}" end diff --git a/Library/Homebrew/test/cask/artifact/manpage_spec.rb b/Library/Homebrew/test/cask/artifact/manpage_spec.rb index b1813dfa7f..a105a8fd51 100644 --- a/Library/Homebrew/test/cask/artifact/manpage_spec.rb +++ b/Library/Homebrew/test/cask/artifact/manpage_spec.rb @@ -8,7 +8,7 @@ describe Cask::Artifact::Manpage, :cask do let(:cask_token) { "invalid/invalid-manpage-no-section" } it "fails to load a cask without section" do - expect { cask }.to raise_error(Cask::CaskInvalidError, /section should be a positive number/) + expect { cask }.to raise_error(Cask::CaskInvalidError, /is not a valid man page name/) end end