Class: Firefox::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/firefox/profile.rb

Overview

A Firefox profile. Allows basic creation and management of a profile. Supports preference setting and addon installation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Profile

Returns a new instance of Profile.



12
13
14
15
# File 'lib/firefox/profile.rb', line 12

def initialize path
  @prefs = Prefs.new(File.join(path,'prefs.js'))
  @addons = Addons.new(File.join(path,'extensions'))
end

Instance Attribute Details

#addonsObject

Returns the value of attribute addons.



10
11
12
# File 'lib/firefox/profile.rb', line 10

def addons
  @addons
end

#prefsObject

Returns the value of attribute prefs.



10
11
12
# File 'lib/firefox/profile.rb', line 10

def prefs
  @prefs
end

Class Method Details

.call_ff_create(path) ⇒ Object



36
37
38
39
# File 'lib/firefox/profile.rb', line 36

def call_ff_create path
  name = File.split(path).last
  %x[#{Base.bin_path} -CreateProfile \"#{name} #{File.realpath(path)}\" 2>&1]
end

.create(path) ⇒ Object

Register a new profile with firefox. This is the right way to initialize a new profile. It checks if the given directory exists, creates it if not



25
26
27
28
29
30
31
32
33
34
# File 'lib/firefox/profile.rb', line 25

def create path
  FileUtils.mkdir_p(path) unless File.directory?(path)
  FileUtils.touch(%W[prefs user].map { |f| File.join(path,"#{f}.js") })
  response = call_ff_create(path)
  if response =~ /Error/
    raise ProfileInitializationError, response
  else
    self.new(path)
  end
end

Instance Method Details

#save!Object



17
18
19
# File 'lib/firefox/profile.rb', line 17

def save!
  self.prefs.write!
end