Class: Orefs::Digest

Inherits:
Object
  • Object
show all
Defined in:
lib/orefs/digest.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Digest) initialize(top_path)

A new instance of Digest



60
61
62
63
64
# File 'lib/orefs/digest.rb', line 60

def initialize(top_path)
  @top_path = top_path
  @version = 0
  @entries = []
end

Instance Attribute Details

- (Object) entries

Returns the value of attribute entries



7
8
9
# File 'lib/orefs/digest.rb', line 7

def entries
  @entries
end

- (Object) top_path (readonly)

Returns the value of attribute top_path



9
10
11
# File 'lib/orefs/digest.rb', line 9

def top_path
  @top_path
end

- (Object) version

Returns the value of attribute version



5
6
7
# File 'lib/orefs/digest.rb', line 5

def version
  @version
end

Class Method Details

+ (Object) create(top, rel_path)



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/orefs/digest.rb', line 11

def self.create(top, rel_path)
  path = (rel_path.nil? || rel_path.empty?) ? top : ::File.join(top, rel_path)
  raise "#{path} is not a directory" unless ::File.directory?(path)
  d = self.new(rel_path)
  ::Dir.foreach(path) do |filename|
    next if filename.start_with?('.')
    child_path = ::File.join(path, filename)
    c = self.create_info(child_path, filename, top)
    d.entries << c
  end
  d
end

+ (Object) create_info(path, filename = nil, top = nil)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/orefs/digest.rb', line 24

def self.create_info(path, filename=nil, top=nil)
  top = $local_top if top.nil?
  filename = ::File.basename(path) if filename.nil?
  stat = ::File.lstat(path)
  if stat.directory?
    c = ::Orefs::Dir.new(filename)
  elsif stat.symlink?
    c = ::Orefs::Link.new(filename)
    c.target = ::File.readlink(path)
    c.target = c.target[top.size + 1..-1] if c.target.start_with?(top)
  elsif stat.file?
    c = ::Orefs::File.new(filename)
    c.size = stat.size()
  else
    raise "file type of #{job.path} is not supported"
  end
  c.mtime = stat.mtime()
  c.mode = stat.mode & 0777
  begin
    c.owner = Etc.getpwuid(stat.uid).name
  rescue
    c.owner = stat.uid
  end
  begin
    c.group = Etc.getgrgid(stat.gid).name
  rescue
    c.group = stat.gid
  end
  c
end

Instance Method Details

- (Object) [](name)



55
56
57
58
# File 'lib/orefs/digest.rb', line 55

def [](name)
  @entries.each { |e| return e if name == e.name }
  nil
end

- (Boolean) empty?

Returns:

  • (Boolean)


66
67
68
# File 'lib/orefs/digest.rb', line 66

def empty?()
  @entries.empty?
end

- (Object) entries_hash



74
75
76
77
78
# File 'lib/orefs/digest.rb', line 74

def entries_hash()
  h = {}
  @entries.each { |e| h[e.name] = e }
  h
end

- (Object) sub_dirs



70
71
72
# File 'lib/orefs/digest.rb', line 70

def sub_dirs()
  @entries.select { |e| e.is_a?(::Orefs::Dir) }
end