lib/firebrew/firefox/command.rb in firebrew-0.1.3 vs lib/firebrew/firefox/command.rb in firebrew-0.2.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'shellwords' + module Firebrew::Firefox class Command class Executer def exec(command) [%x[#{command}], $?] @@ -8,20 +10,36 @@ def initialize(config={}, executer = Executer.new) @config = config @executer = executer begin - result = @executer.exec('"%{firefox}" --version' % @config) - raise Firebrew::FirefoxCommandError unless result[0] =~ /Mozilla Firefox/ - raise Firebrew::FirefoxCommandError unless result[1] == 0 + result = if ENV['OS'].nil? then + @executer.exec('%{firefox} --version' % self.escaped_config) + else + @executer.exec('"%{firefox}" --version' % @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 + raise Firebrew::FirefoxCommandError, 'Firefox command not found: %{firefox}' % @config end end def version - return @version if @version.present? - result = @executer.exec('"%{firefox}" --version' % @config)[0] + return @version unless @version.nil? + result = if ENV['OS'].nil? then + @executer.exec('%{firefox} --version' % self.escaped_config)[0] + else + @executer.exec('"%{firefox}" --version' % @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