Class: Tobacco::Exhaler

Inherits:
Object
  • Object
show all
Defined in:
lib/tobacco/exhaler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/tobacco/exhaler.rb', line 5

def content
  @content
end

#filepathObject

Returns the value of attribute filepath.



5
6
7
# File 'lib/tobacco/exhaler.rb', line 5

def filepath
  @filepath
end

Instance Method Details

#create_directoryObject



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_fileObject



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