Sha256: 96b5deceb9aa799931e4c593a3c990d6baf7dc79f2dcaf73f3200e539e451a6c

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'shellwords'
require 'os'

module Firebrew::Firefox
  class Command
    class Executer
      def exec(command)
        [%x[#{command}], $?]
      end
    end
    
    def initialize(config={}, executer = Executer.new)
      @config = config
      @executer = executer
      begin
        result = if OS.windows? then
          @executer.exec('"%{firefox}" --version' % @config)
        else
          @executer.exec('%{firefox} --version' % self.escaped_config)
        end
        raise Firebrew::FirefoxCommandError, 'Command is not Firefox: %{firefox}' % @config unless result[0] =~ /Mozilla Firefox/
        raise Firebrew::FirefoxCommandError, 'Command is not Firefox: %{firefox}' % @config unless result[1] == 0
      rescue SystemCallError
        raise Firebrew::FirefoxCommandError, 'Firefox command not found: %{firefox}' % @config
      end
    end
    
    def version
      return @version unless @version.nil?
      result = if OS.windows? then
        @executer.exec('"%{firefox}" --version' % @config)[0]
      else
        @executer.exec('%{firefox} --version' % self.escaped_config)[0]
      end
      @version = result.match(/[0-9.]+/)[0]
    end
    
    protected
    
    def escaped_config
      result = @config.clone
      result[:firefox] = Shellwords.escape result[:firefox]
      result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
firebrew-0.3.0 lib/firebrew/firefox/command.rb