Class: Tobacco::Exhaler
- Inherits:
-
Object
- Object
- Tobacco::Exhaler
- Defined in:
- lib/tobacco/exhaler.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
Instance Method Summary collapse
- #create_directory ⇒ Object
-
#initialize(content = '', filepath = '') ⇒ Exhaler
constructor
A new instance of Exhaler.
- #write! ⇒ Object
- #write_content_to_file ⇒ Object
Constructor Details
#initialize(content = '', filepath = '') ⇒ Exhaler
Returns a new instance of Exhaler.
7 8 9 10 |
# File 'lib/tobacco/exhaler.rb', line 7 def initialize(content = '', filepath = '') self.content = content self.filepath = filepath end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/tobacco/exhaler.rb', line 5 def content @content end |
#filepath ⇒ Object
Returns the value of attribute filepath.
5 6 7 |
# File 'lib/tobacco/exhaler.rb', line 5 def filepath @filepath end |
Instance Method Details
#create_directory ⇒ Object
19 20 21 22 23 24 |
# File 'lib/tobacco/exhaler.rb', line 19 def create_directory dir = File.dirname(filepath) FileUtils.mkdir_p dir File.chmod(0775, dir) end |
#write! ⇒ Object
12 13 14 15 16 17 |
# File 'lib/tobacco/exhaler.rb', line 12 def write! # safety_net.backup create_directory write_content_to_file end |
#write_content_to_file ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/tobacco/exhaler.rb', line 26 def write_content_to_file begin persist(content) # safety_net.destroy rescue => e # safety_net.restore raise end end |