Class: Firebrew::Firefox::Extension::Manager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Manager

Returns a new instance of Manager.



11
12
13
# File 'lib/firebrew/firefox/extension.rb', line 11

def initialize(params={})
  @profile = params[:profile]
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



9
10
11
# File 'lib/firebrew/firefox/extension.rb', line 9

def profile
  @profile
end

Instance Method Details

#allObject



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

def all
  profile_extensions = self.fetch['addons'].find_all do |extension|
    extension['location'] == 'app-profile'
  end
  
  profile_extensions.map do |extension|
    Extension.new({
      name: extension['defaultLocale']['name'],
      guid: extension['id'],
      version: extension['version'],
      uri: '%s.xpi' % File.join(self.profile.path, 'extensions', extension['id'])
    }, self)
  end
end

#find(name) ⇒ Object



30
31
32
# File 'lib/firebrew/firefox/extension.rb', line 30

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

#find!(name) ⇒ Object



34
35
36
37
38
# File 'lib/firebrew/firefox/extension.rb', line 34

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

#install(extension) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/firebrew/firefox/extension.rb', line 40

def install(extension)
  dir = File.join(self.profile.path, 'extensions')
  FileUtils.mkdir_p dir
  install_path = '%s.xpi' % File.join(dir, extension.guid)
  
  open(extension.uri, 'rb') do |i|
    open(install_path, 'wb') do |o|
      o.write i.read
    end
  end
  
  self.add(extension)
  self.push
end

#uninstall(extension) ⇒ Object



55
56
57
58
59
# File 'lib/firebrew/firefox/extension.rb', line 55

def uninstall(extension)
  FileUtils.rm_f extension.uri
  self.remove(extension)
  self.push
end