Class: Velcro::Brewfile

Inherits:
Object
  • Object
show all
Includes:
FileHelpers
Defined in:
lib/velcro/brewfile.rb

Constant Summary collapse

DEPENDENCY_FORMAT =
%r{^brew '(?<name>\S*)'(, '(?<version>\S*)')?$}

Instance Method Summary collapse

Methods included from FileHelpers

#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

#contentObject



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

#dependenciesObject



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