Class: Firefox::Prefs

Inherits:
Fondue::HashClass show all
Defined in:
lib/firefox/prefs.rb

Constant Summary collapse

%{# Mozilla User Preferences

/* Do not edit this file.
 *
 * If you make changes to this file while the application is running,
 * the changes will be overwritten when the application exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 */

}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fondue::HashClass

get_hash_attribute, hash_attribute, #method_missing, stringify

Constructor Details

#initialize(path_to_prefs) ⇒ Prefs

Returns a new instance of Prefs.



19
20
21
22
23
24
# File 'lib/firefox/prefs.rb', line 19

def initialize path_to_prefs
  @path = path_to_prefs
  @prefs = {}
  @types = {}
  parse_prefs!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Fondue::HashClass

Instance Attribute Details

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#prefsObject

Returns the value of attribute prefs.



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

def prefs
  @prefs
end

#raw_prefsObject

Returns the value of attribute raw_prefs.



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

def raw_prefs
  @raw_prefs
end

Instance Method Details

#stringified_prefsObject



31
32
33
34
35
36
37
38
# File 'lib/firefox/prefs.rb', line 31

def stringified_prefs
  string = ''
  string << BANNER
  string << @prefs.map { |key,val| 
    %{user_pref("#{key}", #{val.is_a?(String) ? %{"#{val}"} : val});}
  }.join("\n")
  string << "\n"
end

#write!(write_path = '') ⇒ Object



26
27
28
29
# File 'lib/firefox/prefs.rb', line 26

def write! write_path = ''
  path = write_path == '' ? @path : write_path
  File.open(path,'w') { |f| f.write(stringified_prefs) }
end