Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
a1674690
Commit
a1674690
authored
7 years ago
by
Markus Reiter
Browse files
Options
Downloads
Patches
Plain Diff
Add `PATH` class.
parent
e221d048
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Library/Homebrew/PATH.rb
+61
-0
61 additions, 0 deletions
Library/Homebrew/PATH.rb
Library/Homebrew/global.rb
+1
-0
1 addition, 0 deletions
Library/Homebrew/global.rb
Library/Homebrew/test/PATH_spec.rb
+52
-0
52 additions, 0 deletions
Library/Homebrew/test/PATH_spec.rb
with
114 additions
and
0 deletions
Library/Homebrew/PATH.rb
0 → 100644
+
61
−
0
View file @
a1674690
class
PATH
def
initialize
(
*
paths
)
@paths
=
parse
(
*
paths
)
end
def
prepend
(
*
paths
)
@paths
.
unshift
(
*
parse
(
*
paths
))
self
end
def
append
(
*
paths
)
@paths
.
concat
(
parse
(
*
paths
))
self
end
def
to_ary
@paths
end
alias
to_a
to_ary
def
to_str
@paths
.
join
(
File
::
PATH_SEPARATOR
)
end
alias
to_s
to_str
def
eql?
(
other
)
if
other
.
respond_to?
(
:to_ary
)
return
true
if
to_ary
==
other
.
to_ary
end
if
other
.
respond_to?
(
:to_str
)
return
true
if
to_str
==
other
.
to_str
end
false
end
alias
==
eql?
def
empty?
@paths
.
empty?
end
def
inspect
"<PATH#
#{
to_str
}
>"
end
def
validate
self
.
class
.
new
(
@paths
.
select
(
&
File
.
method
(
:directory?
)))
end
private
def
parse
(
*
paths
)
paths
.
flatten
.
flat_map
{
|
p
|
p
.
respond_to?
(
:to_str
)
?
p
.
to_str
.
split
(
File
::
PATH_SEPARATOR
):
p
}
.
compact
.
map
{
|
p
|
p
.
respond_to?
(
:to_path
)
?
p
.
to_path
:
p
.
to_str
}
.
uniq
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/global.rb
+
1
−
0
View file @
a1674690
...
...
@@ -3,6 +3,7 @@ require "extend/fileutils"
require
"extend/pathname"
require
"extend/git_repository"
require
"extend/ARGV"
require
"PATH"
require
"extend/string"
require
"os"
require
"utils"
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/PATH_spec.rb
0 → 100644
+
52
−
0
View file @
a1674690
require
"PATH"
describe
PATH
do
describe
"#initialize"
do
it
"can take multiple arguments"
do
expect
(
described_class
.
new
(
"/path1"
,
"/path2"
)).
to
eq
(
"/path1:/path2"
)
end
it
"can parse a mix of arrays and arguments"
do
expect
(
described_class
.
new
([
"/path1"
,
"/path2"
],
"/path3"
)).
to
eq
(
"/path1:/path2:/path3"
)
end
it
"splits an existing PATH"
do
expect
(
described_class
.
new
(
"/path1:/path2"
)).
to
eq
([
"/path1"
,
"/path2"
])
end
end
describe
"#to_ary"
do
it
"returns a PATH array"
do
expect
(
described_class
.
new
(
"/path1"
,
"/path2"
).
to_ary
).
to
eq
([
"/path1"
,
"/path2"
])
end
end
describe
"#to_str"
do
it
"returns a PATH string"
do
expect
(
described_class
.
new
(
"/path1"
,
"/path2"
).
to_str
).
to
eq
(
"/path1:/path2"
)
end
end
describe
"#prepend"
do
it
"prepends a path to a PATH"
do
expect
(
described_class
.
new
(
"/path1"
).
prepend
(
"/path2"
).
to_str
).
to
eq
(
"/path2:/path1"
)
end
end
describe
"#append"
do
it
"prepends a path to a PATH"
do
expect
(
described_class
.
new
(
"/path1"
).
append
(
"/path2"
).
to_str
).
to
eq
(
"/path1:/path2"
)
end
end
describe
"#validate"
do
it
"returns a new PATH without non-existent paths"
do
allow
(
File
).
to
receive
(
:directory?
).
with
(
"/path1"
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:directory?
).
with
(
"/path2"
).
and_return
(
false
)
path
=
described_class
.
new
(
"/path1"
,
"/path2"
)
expect
(
path
.
validate
.
to_ary
).
to
eq
([
"/path1"
])
expect
(
path
.
to_ary
).
to
eq
([
"/path1"
,
"/path2"
])
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment