Class: SimpleView::FileContent
- Inherits:
-
Object
- Object
- SimpleView::FileContent
- Defined in:
- lib/simple_view/file_content.rb
Constant Summary collapse
- NO_READ =
:no_read
Instance Attribute Summary collapse
-
#file(set_content_no_read = false) ⇒ Object
Returns the value of attribute file.
-
#last_modification ⇒ Object
Returns the value of attribute last_modification.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #content ⇒ Object
-
#initialize(file) ⇒ FileContent
constructor
A new instance of FileContent.
Constructor Details
#initialize(file) ⇒ FileContent
Returns a new instance of FileContent.
8 9 10 11 |
# File 'lib/simple_view/file_content.rb', line 8 def initialize(file) self.file = file self.last_modification = File.mtime(self.file) end |
Instance Attribute Details
#file(set_content_no_read = false) ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/simple_view/file_content.rb', line 6 def file @file end |
#last_modification ⇒ Object
Returns the value of attribute last_modification.
6 7 8 |
# File 'lib/simple_view/file_content.rb', line 6 def last_modification @last_modification end |
Class Method Details
.changed?(file) ⇒ Boolean
43 44 45 |
# File 'lib/simple_view/file_content.rb', line 43 def changed?(file) self.file(file).changed? end |
.file(file) ⇒ Object
38 39 40 41 |
# File 'lib/simple_view/file_content.rb', line 38 def file(file) return nil unless file self.files[file] ||= self.new(file) end |
.files ⇒ Object
34 35 36 |
# File 'lib/simple_view/file_content.rb', line 34 def files @files ||= {} end |
Instance Method Details
#changed? ⇒ Boolean
21 22 23 |
# File 'lib/simple_view/file_content.rb', line 21 def changed? @content.nil? || (File.mtime(self.file) > self.last_modification) end |
#content ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/simple_view/file_content.rb', line 13 def content if changed? || @content == NO_READ @content = File.read(self.file) self.last_modification = File.mtime(self.file) end @content end |