Class: Rubu::State

Inherits:
Object
  • Object
show all
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)

Class Method Details

+ (Object) load

Load state.



24
25
26
27
28
# File 'lib/rubu.rb', line 24

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.

Parameters:

  • file

    File.

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubu.rb', line 40

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.

Parameters:

  • file

    File.



33
34
35
# File 'lib/rubu.rb', line 33

def State.md5_gen( file )
    Digest::MD5.hexdigest( File.read( file ) )
end

+ (Object) save

Save state.



17
18
19
20
21
# File 'lib/rubu.rb', line 17

def State.save
    if @@md5.any?
        IO.write( @@state_file, YAML.dump( @@md5 ) )
    end
end