Sha256: 5026e73babb363fb902315455e7ba170e0c6041dd991806e330695148d5b7abc

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module Vintner
  class Parser

    def initialize
      
    end

    protected
    def installed?(name)
      installed = `brew list #{name} -v`.split(/\s/)
      if installed.size > 0
        return installed.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

3 entries across 3 versions & 1 rubygems

Version Path
vintner-1.2 lib/vintner/parser.rb
vintner-1.1 lib/vintner/parser.rb
vintner-1.0 lib/vintner/parser.rb