Class: FileInfoRW
- Inherits:
-
Object
- Object
- FileInfoRW
- Defined in:
- lib/FileInfo.rb
Instance Method Summary collapse
-
#create_cache ⇒ Object
Create the cache file.
-
#file_has_changed? ⇒ Boolean
Read the info file and write a new one if needed Report back if the file has changed.
-
#initialize(file_loc, file_path) ⇒ FileInfoRW
constructor
file_loc = cache file location file_path = path of the file that represents the cache file.
Constructor Details
#initialize(file_loc, file_path) ⇒ FileInfoRW
file_loc = cache file location file_path = path of the file that represents the cache file
10 11 12 13 |
# File 'lib/FileInfo.rb', line 10 def initialize(file_loc, file_path) @file_loc = file_loc @file_path = file_path end |
Instance Method Details
#create_cache ⇒ Object
Create the cache file
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/FileInfo.rb', line 32 def create_cache() json = self._json dirnames = File.dirname(@file_loc) unless File.directory?(dirnames) # Directories do not exist, create them FileUtils.mkdir_p(dirnames) end File.write(@file_loc, json) end |
#file_has_changed? ⇒ Boolean
Read the info file and write a new one if needed Report back if the file has changed
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/FileInfo.rb', line 17 def file_has_changed?() cache_file = File.open(@file_loc) file_info = JSON.parse(cache_file.read, object_class: OpenStruct) last_modified = File.mtime(@file_path).to_i if last_modified > file_info.date json = self._json File.write(@file_loc, json) return true else return false end end |