Sha256: 522c48b4bec269df7cb0e4fd77efb8810ef493de5d6ac95f7d96e09f53d74efd

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Vint
  class Parser

    def initialize
      
    end

    protected
    def installed?(name)
      info = `brew info #{name}`.split(/\n/)
      if (info =~ /Error: /) || info.reverse[1] =~ /Not installed/
        return false
      else
        return info[0].split(": ").last
      end
    end

    def install(name, args={})
      brewable = `brew info #{name}`
      if brewable =~ /^Error:/
        puts "Error: No available formula for #{name}"
        exit 1
      end
      if args[:url]
        system "brew install #{args[:url]} >& /dev/null"
      else
        system "brew install #{name} >& /dev/null"
      end
    end

    def brew(formula, args={})
      installed_version = installed?(formula)
      puts "#{installed_version ? "Using" : "Installing"} #{formula} #{installed_version ? "(#{installed_version})" : "..."}"
      install(formula, args) unless installed_version
    end

    public
    def parse(brewfile)
      begin
        eval(File.open(brewfile).read)
        puts "All of formula in Brewfile is installed!"
      rescue => e
        puts e
        exit 1
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vint-1.3 lib/vint/parser.rb