mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Create method ruby_file?
Both formula_files and cask_files need to check whether a file is a Ruby file. Also, use this method in formula_file? and cask_file?
This commit is contained in:
parent
6ac30826d0
commit
0fcdc9ba07
@ -382,7 +382,7 @@ class Tap
|
|||||||
# an array of all {Formula} files of this {Tap}.
|
# an array of all {Formula} files of this {Tap}.
|
||||||
def formula_files
|
def formula_files
|
||||||
@formula_files ||= if formula_dir.directory?
|
@formula_files ||= if formula_dir.directory?
|
||||||
formula_dir.children.select { |file| file.extname == ".rb" }
|
formula_dir.children.select(&method(:ruby_file?))
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@ -391,19 +391,25 @@ class Tap
|
|||||||
# an array of all {Cask} files of this {Tap}.
|
# an array of all {Cask} files of this {Tap}.
|
||||||
def cask_files
|
def cask_files
|
||||||
@cask_files ||= if cask_dir.directory?
|
@cask_files ||= if cask_dir.directory?
|
||||||
cask_dir.children.select { |file| file.extname == ".rb" }
|
cask_dir.children.select(&method(:ruby_file?))
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns true if the file has a Ruby extension
|
||||||
|
# @private
|
||||||
|
def ruby_file?(file)
|
||||||
|
file.extname == ".rb"
|
||||||
|
end
|
||||||
|
|
||||||
# return true if given path would present a {Formula} file in this {Tap}.
|
# return true if given path would present a {Formula} file in this {Tap}.
|
||||||
# accepts both absolute path and relative path (relative to this {Tap}'s path)
|
# accepts both absolute path and relative path (relative to this {Tap}'s path)
|
||||||
# @private
|
# @private
|
||||||
def formula_file?(file)
|
def formula_file?(file)
|
||||||
file = Pathname.new(file) unless file.is_a? Pathname
|
file = Pathname.new(file) unless file.is_a? Pathname
|
||||||
file = file.expand_path(path)
|
file = file.expand_path(path)
|
||||||
file.extname == ".rb" && file.parent == formula_dir
|
ruby_file?(file) && file.parent == formula_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
# return true if given path would present a {Cask} file in this {Tap}.
|
# return true if given path would present a {Cask} file in this {Tap}.
|
||||||
@ -412,7 +418,7 @@ class Tap
|
|||||||
def cask_file?(file)
|
def cask_file?(file)
|
||||||
file = Pathname.new(file) unless file.is_a? Pathname
|
file = Pathname.new(file) unless file.is_a? Pathname
|
||||||
file = file.expand_path(path)
|
file = file.expand_path(path)
|
||||||
file.extname == ".rb" && file.parent == cask_dir
|
ruby_file?(file) && file.parent == cask_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
# an array of all {Formula} names of this {Tap}.
|
# an array of all {Formula} names of this {Tap}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user