Class: Firebrew::Runner
- Inherits:
-
Object
- Object
- Firebrew::Runner
- Defined in:
- lib/firebrew/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#profile ⇒ Object
Returns the value of attribute profile.
Class Method Summary collapse
Instance Method Summary collapse
- #info(params = {}) ⇒ Object
-
#initialize(config = {}, is_displaying_progress = false) ⇒ Runner
constructor
A new instance of Runner.
- #install(params = {}) ⇒ Object
- #list(params = {}) ⇒ Object
- #search(params = {}) ⇒ Object
- #select_profile(name = nil) ⇒ Object
- #uninstall(params = {}) ⇒ Object
Constructor Details
#initialize(config = {}, is_displaying_progress = false) ⇒ Runner
Returns a new instance of Runner.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/firebrew/runner.rb', line 38 def initialize(config={}, = false) self.config = self.class.default_config.merge(config) @is_displaying_progress = @profile_manager = Firefox::Profile::Manager.new( base_dir: self.config[:base_dir], data_file: self.config[:data_file] ) @firefox = Firefox::Command.new(self.config) self.select_profile end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/firebrew/runner.rb', line 8 def config @config end |
#profile ⇒ Object
Returns the value of attribute profile.
8 9 10 |
# File 'lib/firebrew/runner.rb', line 8 def profile @profile end |
Class Method Details
.default_config ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/firebrew/runner.rb', line 10 def self.default_config result = { base_dir: ENV['FIREBREW_FIREFOX_PROFILE_BASE_DIR'], firefox: ENV['FIREBREW_FIREFOX'], profile: ENV['FIREBREW_FIREFOX_PROFILE'] || 'default', } if OS.mac? then result[:base_dir] ||= '~/Library/Application Support/Firefox' result[:firefox] ||= '/Applications/Firefox.app/Contents/MacOS/firefox-bin' result[:os] = 'darwin' elsif OS.linux? then result[:base_dir] ||= '~/.mozilla/firefox' result[:firefox] ||= '/usr/bin/firefox' result[:os] = 'linux' elsif OS.windows? then appdata = ENV['APPDATA'].to_s.gsub('\\','/') programfiles = (ENV['PROGRAMFILES(X86)'] || ENV['PROGRAMFILES']).to_s.gsub('\\','/') result[:base_dir] ||= File.join(appdata, 'Mozilla/Firefox') result[:firefox] ||= File.join(programfiles, 'Mozilla Firefox/firefox.exe') result[:os] = 'winnt' end result end |
Instance Method Details
#info(params = {}) ⇒ Object
70 71 72 |
# File 'lib/firebrew/runner.rb', line 70 def info(params={}) self.fetch_api(term: params[:term], max: 1).first end |
#install(params = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/firebrew/runner.rb', line 55 def install(params={}) extension = self.profile.extensions.find(params[:term]) raise Firebrew::OperationAlreadyCompletedError, "Already installed: #{params[:term]}" unless extension.nil? result = self.fetch_api(term: params[:term], max: 1).first self.profile.extensions.install(result, @is_displaying_progress) end |
#list(params = {}) ⇒ Object
74 75 76 |
# File 'lib/firebrew/runner.rb', line 74 def list(params={}) self.profile.extensions.all end |
#search(params = {}) ⇒ Object
78 79 80 |
# File 'lib/firebrew/runner.rb', line 78 def search(params={}) self.fetch_api(term: params[:term]) end |
#select_profile(name = nil) ⇒ Object
51 52 53 |
# File 'lib/firebrew/runner.rb', line 51 def select_profile(name = nil) self.profile = @profile_manager.find!(name || self.config[:profile]) end |
#uninstall(params = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/firebrew/runner.rb', line 62 def uninstall(params={}) begin self.profile.extensions.find!(params[:term]).delete rescue Firebrew::ExtensionNotFoundError raise Firebrew::OperationAlreadyCompletedError, "Already uninstalled: #{params[:term]}" end end |