Module: Spectra::Serializable
- Included in:
- View
- Defined in:
- lib/spectra/views/serializable.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #destination(attributes) ⇒ Object
- #serialize(attributes) ⇒ Object
- #write_file(file, text, path) ⇒ Object
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
6 7 8 |
# File 'lib/spectra/views/serializable.rb', line 6 def directory @directory end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/spectra/views/serializable.rb', line 6 def filename @filename end |
Instance Method Details
#destination(attributes) ⇒ Object
32 33 34 35 36 |
# File 'lib/spectra/views/serializable.rb', line 32 def destination(attributes) destination = self.directory destination << '/' unless destination.end_with?('/') destination + self.filename end |
#serialize(attributes) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spectra/views/serializable.rb', line 8 def serialize(attributes) text = self.render(attributes) path = self.destination(attributes) begin file = File.open(path, 'w+') rescue Exception raise Informative, "Couldn't open #{path}" else self.write_file(file, text, path) ensure file.close unless file.nil? end end |