Pass section to the constructor
This commit is contained in:
parent
22d821323c
commit
87f29857f0
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user