Class: Tobacco::Smoker
- Inherits:
-
Object
- Object
- Tobacco::Smoker
- Defined in:
- lib/tobacco/smoker.rb
Instance Attribute Summary collapse
-
#consumer ⇒ Object
Returns the value of attribute consumer.
-
#content ⇒ Object
Returns the value of attribute content.
-
#file_path_generator ⇒ Object
Returns the value of attribute file_path_generator.
-
#persister ⇒ Object
Returns the value of attribute persister.
-
#reader ⇒ Object
Returns the value of attribute reader.
Instance Method Summary collapse
-
#continue_write ⇒ Object
Public: Called by ContentValidator if content is valid.
- #filepath ⇒ Object
- #generate_file_paths ⇒ Object
-
#initialize(consumer, content = nil) ⇒ Smoker
constructor
A new instance of Smoker.
- #read ⇒ Object
-
#write! ⇒ Object
Public: Writes content to file allowing for manipulation of the content beforehand through the :before_write callback This is due to the fact that content can be set directly without going through the read method.
Constructor Details
Instance Attribute Details
#consumer ⇒ Object
Returns the value of attribute consumer.
4 5 6 |
# File 'lib/tobacco/smoker.rb', line 4 def consumer @consumer end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/tobacco/smoker.rb', line 4 def content @content end |
#file_path_generator ⇒ Object
Returns the value of attribute file_path_generator.
4 5 6 |
# File 'lib/tobacco/smoker.rb', line 4 def file_path_generator @file_path_generator end |
#persister ⇒ Object
Returns the value of attribute persister.
4 5 6 |
# File 'lib/tobacco/smoker.rb', line 4 def persister @persister end |
#reader ⇒ Object
Returns the value of attribute reader.
4 5 6 |
# File 'lib/tobacco/smoker.rb', line 4 def reader @reader end |
Instance Method Details
#continue_write ⇒ Object
Public: Called by ContentValidator if content is valid
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tobacco/smoker.rb', line 42 def continue_write begin content_writer = Tobacco::Exhaler.new(content, filepath) content_writer.write! Tobacco::Callback.instance.notify(:on_success, content) rescue => e Tobacco.log("ErrorWriting: #{filepath}\nError: #{e}") error = error_object('Error Writing', e) Tobacco::Callback.instance.notify(:on_write_error, error) # raise end end |
#filepath ⇒ Object
59 60 61 |
# File 'lib/tobacco/smoker.rb', line 59 def filepath @filepath ||= file_path_generator.output_filepath end |
#generate_file_paths ⇒ Object
19 20 21 |
# File 'lib/tobacco/smoker.rb', line 19 def generate_file_paths self.file_path_generator = Tobacco::Roller.new(consumer) end |
#read ⇒ Object
23 24 25 |
# File 'lib/tobacco/smoker.rb', line 23 def read self.content = Tobacco::ContentReader.new(self).read end |
#write! ⇒ Object
Public: Writes content to file allowing for manipulation of the content beforehand through the :before_write callback This is due to the fact that content can be set directly without going through the read method.
Validate is only in the write method because the content can be set directly and the read method never called.
36 37 38 |
# File 'lib/tobacco/smoker.rb', line 36 def write! Tobacco::ContentValidator.new(self).validate! end |