Class: Tobacco::ContentReader
- Inherits:
-
Object
- Object
- Tobacco::ContentReader
- Defined in:
- lib/tobacco/content_reader.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#modified_content ⇒ Object
Returns the value of attribute modified_content.
-
#reader ⇒ Object
Returns the value of attribute reader.
Instance Method Summary collapse
-
#choose_reader ⇒ Object
The reader will either be the calling class (consumer) if it provides the content method or a new Inhaler object that will be used to read the content from a url.
-
#initialize(smoker) ⇒ ContentReader
constructor
A new instance of ContentReader.
- #modify_content ⇒ Object
- #read ⇒ Object
- #read_content ⇒ Object
Constructor Details
#initialize(smoker) ⇒ ContentReader
Returns a new instance of ContentReader.
5 6 7 8 9 |
# File 'lib/tobacco/content_reader.rb', line 5 def initialize(smoker) @smoker = smoker @consumer = smoker.consumer @filepath = smoker.file_path_generator end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/tobacco/content_reader.rb', line 3 def content @content end |
#modified_content ⇒ Object
Returns the value of attribute modified_content.
3 4 5 |
# File 'lib/tobacco/content_reader.rb', line 3 def modified_content @modified_content end |
#reader ⇒ Object
Returns the value of attribute reader.
3 4 5 |
# File 'lib/tobacco/content_reader.rb', line 3 def reader @reader end |
Instance Method Details
#choose_reader ⇒ Object
The reader will either be the calling class (consumer) if it provides the content method or a new Inhaler object that will be used to read the content from a url
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tobacco/content_reader.rb', line 30 def choose_reader self.reader = \ if @consumer.respond_to? Tobacco.content_method @consumer else Inhaler.new(@filepath.content_url).tap do |inhaler| # Add an alias for the user configured content_method # so that when it is called it calls :read # on the Inhaler instance # inhaler.instance_eval %{ alias :"#{Tobacco.content_method}" :read } end end end |
#modify_content ⇒ Object
17 18 19 20 |
# File 'lib/tobacco/content_reader.rb', line 17 def modify_content self.modified_content = \ Tobacco::Callback.instance.notify(:before_write, content) end |
#read ⇒ Object
11 12 13 14 15 |
# File 'lib/tobacco/content_reader.rb', line 11 def read choose_reader read_content modify_content end |
#read_content ⇒ Object
22 23 24 |
# File 'lib/tobacco/content_reader.rb', line 22 def read_content self.content = reader.send(Tobacco.content_method) end |