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 Cask
|
||||||
module Artifact
|
module Artifact
|
||||||
class Manpage < Symlinked
|
class Manpage < Symlinked
|
||||||
|
attr_reader :section
|
||||||
|
|
||||||
def self.from_args(cask, source)
|
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
|
end
|
||||||
|
|
||||||
def initialize(cask, source)
|
def initialize(cask, source, section)
|
||||||
super
|
@section = section
|
||||||
|
|
||||||
|
super(cask, source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_target(_target)
|
def resolve_target(_target)
|
||||||
config.manpagedir.join("man#{section}", target_name)
|
config.manpagedir.join("man#{section}", target_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def section
|
|
||||||
@source.extname.downcase[1..-1].to_s.to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def target_name
|
def target_name
|
||||||
"#{@source.basename(@source.extname)}.#{section}"
|
"#{@source.basename(@source.extname)}.#{section}"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,7 @@ describe Cask::Artifact::Manpage, :cask do
|
|||||||
let(:cask_token) { "invalid/invalid-manpage-no-section" }
|
let(:cask_token) { "invalid/invalid-manpage-no-section" }
|
||||||
|
|
||||||
it "fails to load a cask without section" do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user