Class: Velcro::Brewfile
Constant Summary
collapse
- DEPENDENCY_FORMAT =
%r{^brew '(?<name>\S*)'(, '(?<version>\S*)')?$}
Instance Method Summary
collapse
#location, #recursive_search
Instance Method Details
#brewfile_in(directory) ⇒ Object
37
38
39
|
# File 'lib/velcro/brewfile.rb', line 37
def brewfile_in(directory)
File.join(directory, 'Brewfile')
end
|
#content ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/velcro/brewfile.rb', line 29
def content
if location
File.read(brewfile_in(location))
else
fail BrewfileNotFound, 'Could not locate Brewfile'
end
end
|
#dependencies ⇒ Object
11
12
13
|
# File 'lib/velcro/brewfile.rb', line 11
def dependencies
parse_dependencies(content)
end
|
#parse_dependencies(content) ⇒ Object
15
16
17
18
19
|
# File 'lib/velcro/brewfile.rb', line 15
def parse_dependencies(content)
content.split("\n").map do |line|
parse_line(line)
end.flatten.compact
end
|
#parse_line(line) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/velcro/brewfile.rb', line 21
def parse_line(line)
if line.match(/^brew/)
line.scan(DEPENDENCY_FORMAT).map do |name, version|
OpenStruct.new(name: name, version: version)
end
end
end
|