Class: ODisk::Digest
- Inherits:
-
Object
- Object
- ODisk::Digest
- Defined in:
- lib/odisk/digest.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#top_path ⇒ Object
readonly
Returns the value of attribute top_path.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #delete(name) ⇒ Object
- #empty? ⇒ Boolean
- #entries_hash ⇒ Object
-
#initialize(top_path) ⇒ Digest
constructor
A new instance of Digest.
- #sub_dirs ⇒ Object
Constructor Details
#initialize(top_path) ⇒ Digest
Returns a new instance of Digest.
55 56 57 58 59 |
# File 'lib/odisk/digest.rb', line 55 def initialize(top_path) @top_path = top_path @version = 0 @entries = [] end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
7 8 9 |
# File 'lib/odisk/digest.rb', line 7 def entries @entries end |
#top_path ⇒ Object (readonly)
Returns the value of attribute top_path.
9 10 11 |
# File 'lib/odisk/digest.rb', line 9 def top_path @top_path end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/odisk/digest.rb', line 5 def version @version end |
Class Method Details
.create(top, rel_path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/odisk/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 |
.create_info(path, filename = nil, top = nil) ⇒ Object
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/odisk/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 = ::ODisk::Dir.new(filename) elsif stat.symlink? c = ::ODisk::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 = ::ODisk::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
#[](name) ⇒ Object
61 62 63 64 |
# File 'lib/odisk/digest.rb', line 61 def [](name) @entries.each { |e| return e if name == e.name } nil end |
#delete(name) ⇒ Object
70 71 72 |
# File 'lib/odisk/digest.rb', line 70 def delete(name) @entries.delete_if { |e| name == e.name } end |
#empty? ⇒ Boolean
66 67 68 |
# File 'lib/odisk/digest.rb', line 66 def empty?() @entries.empty? end |
#entries_hash ⇒ Object
78 79 80 81 82 |
# File 'lib/odisk/digest.rb', line 78 def entries_hash() h = {} @entries.each { |e| h[e.name] = e } h end |