Module: LetsCert::FileIOPluginMixin
- Included in:
- AccountKey, CertFile, ChainFile, KeyFile
- Defined in:
- lib/letscert/io_plugin.rb
Overview
Mixin for IOPmugin subclasses that handle files
Instance Method Summary collapse
-
#load ⇒ Hash
Load data from file named #name.
- #load_from_content(content) ⇒ Hash abstract
-
#save_to_file(data) ⇒ void
Save data to file #name.
Instance Method Details
#load ⇒ Hash
Load data from file named #name
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/letscert/io_plugin.rb', line 95 def load logger.debug { "Loading #@name" } begin content = File.read(@name) rescue SystemCallError => ex if ex.is_a? Errno::ENOENT logger.info { "no #@name file" } return self.class.empty_data end raise end load_from_content(content) end |
#load_from_content(content) ⇒ Hash
This method is abstract.
113 114 115 |
# File 'lib/letscert/io_plugin.rb', line 113 def load_from_content(content) raise NotImplementedError end |
#save_to_file(data) ⇒ void
This method returns an undefined value.
Save data to file #name
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/letscert/io_plugin.rb', line 120 def save_to_file(data) return if data.nil? logger.info { "saving #@name" } begin File.open(name, 'w') do |f| f.write(data) end rescue Errno => ex @logger.error { ex. } raise Error, "Error when saving #@name" end end |