Avoid slow operations in FormulaPin#initialize
A FormulaPin object is created every time Formula is instantiated, so don't do filesystem operations or Pathname concatenation eagerly.
This commit is contained in:
parent
b258bee44e
commit
1bad199776
@ -6,13 +6,16 @@ class FormulaPin
|
|||||||
def initialize(formula)
|
def initialize(formula)
|
||||||
@formula = formula
|
@formula = formula
|
||||||
@name = formula.name
|
@name = formula.name
|
||||||
HOMEBREW_PINNED.mkdir unless HOMEBREW_PINNED.exist?
|
end
|
||||||
@path = HOMEBREW_PINNED+@name
|
|
||||||
|
def path
|
||||||
|
HOMEBREW_PINNED+@name
|
||||||
end
|
end
|
||||||
|
|
||||||
def pin_at(version)
|
def pin_at(version)
|
||||||
|
HOMEBREW_PINNED.mkpath unless HOMEBREW_PINNED.exist?
|
||||||
version_path = @formula.installed_prefix.parent.join(version)
|
version_path = @formula.installed_prefix.parent.join(version)
|
||||||
FileUtils.ln_s version_path, @path unless pinned? or not version_path.exist?
|
FileUtils.ln_s version_path, path unless pinned? or not version_path.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
def pin
|
def pin
|
||||||
@ -22,11 +25,11 @@ class FormulaPin
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unpin
|
def unpin
|
||||||
FileUtils.rm @path if pinned?
|
FileUtils.rm path if pinned?
|
||||||
end
|
end
|
||||||
|
|
||||||
def pinned?
|
def pinned?
|
||||||
@path.symlink?
|
path.symlink?
|
||||||
end
|
end
|
||||||
|
|
||||||
def pinable?
|
def pinable?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user