Class: Rubu::State
- Inherits:
-
Object
- Object
- Rubu::State
- Defined in:
- lib/rubu.rb
Overview
Persistent state of Rubu.
State maintains YAML based state file (if in use). The file include MD5 checksums of file content.
Constant Summary
- @@md5 =
{}
- @@state_file =
".rubu_state.yml"
Class Method Summary (collapse)
-
+ (Object) load
Load state.
-
+ (Boolean) md5_check_and_update?(file)
Check for existing checksum and update it if needed.
-
+ (Object) md5_gen(file)
Generate MD5 checksum for file.
-
+ (Object) save
Save state.
Class Method Details
+ (Object) load
Load state.
25 26 27 28 29 |
# File 'lib/rubu.rb', line 25 def State.load if File.exist?( @@state_file ) @@md5 = YAML.load_file( @@state_file ) end end |
+ (Boolean) md5_check_and_update?(file)
Check for existing checksum and update it if needed.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubu.rb', line 41 def State.md5_check_and_update?( file ) if @@md5[ file ] md5 = State.md5_gen( file ) if md5 != @@md5[ file ] @@md5[ file ] = md5 return true end return false else @@md5[ file ] = State.md5_gen( file ) return true end end |
+ (Object) md5_gen(file)
Generate MD5 checksum for file.
34 35 36 |
# File 'lib/rubu.rb', line 34 def State.md5_gen( file ) Digest::MD5.hexdigest( File.read( file ) ) end |
+ (Object) save
Save state.
18 19 20 21 22 |
# File 'lib/rubu.rb', line 18 def State.save if @@md5.any? IO.write( @@state_file, YAML.dump( @@md5 ) ) end end |