Module: Rnote::ConfigFile
- Included in:
- AuthCache, SearchCache
- Defined in:
- lib/rnote/persister.rb
Instance Method Summary collapse
Instance Method Details
#modify_config ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rnote/persister.rb', line 35 def modify_config raise if self.methods.include?(:readonly) and readonly # TODO lock the file through this process config = {} if File.exists?(@config_file) config = YAML.load_file(@config_file) end result = yield config # TODO unlink is unnecessary, just truncate the file and write the new content. # this will keep permissions and lock File.unlink(@config_file) if File.exists?(@config_file) File.open(@config_file, 'w') do |f| f.write header if self.methods.include? :header f.write config.to_yaml after_vivify if self.methods.include? :after_vivify end result end |
#read_config {|config| ... } ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/rnote/persister.rb', line 60 def read_config config = {} if File.exists?(@config_file) config = YAML.load_file(@config_file) end yield config end |