Class: Firebrew::Firefox::Profile::Manager

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

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Manager

Returns a new instance of Manager.



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

def initialize(params={})
  @base_dir = params[:base_dir]
  @data_file = params[:data_file] || 'profiles.ini'
  raise Firebrew::ProfilesFileNotFoundError unless File.exists? self.data_path
end

Instance Method Details

#allObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/firebrew/firefox/profile.rb', line 16

def all
  sections = IniFile.load(self.data_path).to_h
  profiles = sections.find_all{|(name,prop)| name.match(/^Profile\d+$/)}
  profiles.map do |(name,prop)|
    Profile.new(
      name: prop['Name'],
      path: self.profile_path(prop['Path'], prop['IsRelative'] == '1'),
      is_default: prop['Default'] == '1',
    )
  end
end

#find(name) ⇒ Object



28
29
30
# File 'lib/firebrew/firefox/profile.rb', line 28

def find(name)
  self.all.find{|p| p.name == name }
end

#find!(name) ⇒ Object



32
33
34
35
36
# File 'lib/firebrew/firefox/profile.rb', line 32

def find!(name)
  result = self.find(name)
  raise Firebrew::ProfileNotFoundError if result.nil?
  result
end