Class: FileTreeProfiler::DirFile
- Defined in:
- lib/file_tree_profiler/dir_file.rb
Constant Summary collapse
- EMPTY_CHECKSUM =
::Digest::MD5.hexdigest('/no-children/').freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Attributes inherited from File
Instance Method Summary collapse
-
#checksum ⇒ Object
checksum generated using concatenated checksums of all children.
- #empty? ⇒ Boolean
-
#initialize(*args) ⇒ DirFile
constructor
A new instance of DirFile.
- #size ⇒ Object
-
#walk ⇒ Object
collects all children as DirFile or DataFile objects and is invoked on each collected DirFile object.
Methods inherited from File
#inspect, #path, #relative_path
Constructor Details
#initialize(*args) ⇒ DirFile
Returns a new instance of DirFile.
6 7 8 9 |
# File 'lib/file_tree_profiler/dir_file.rb', line 6 def initialize *args super *args walk end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/file_tree_profiler/dir_file.rb', line 4 def children @children end |
Instance Method Details
#checksum ⇒ Object
checksum generated using concatenated checksums of all children
36 37 38 39 40 41 42 43 44 |
# File 'lib/file_tree_profiler/dir_file.rb', line 36 def checksum @checksum ||= begin if empty? EMPTY_CHECKSUM else ::Digest::MD5.hexdigest(children.map(&:checksum).join) end end.to_s end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/file_tree_profiler/dir_file.rb', line 27 def empty? children.empty? end |
#size ⇒ Object
31 32 33 |
# File 'lib/file_tree_profiler/dir_file.rb', line 31 def size children.inject(1) {|sum, c| sum += c.size; sum } end |
#walk ⇒ Object
collects all children as DirFile or DataFile objects and is invoked on each collected DirFile object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/file_tree_profiler/dir_file.rb', line 13 def walk FileTreeProfiler.monitor_report(:profile, :dir, path) @children = [] Dir.foreach(path) do |entry| next if (entry == '..' || entry == '.') full_path = ::File.join(path, entry) if ::File.directory?(full_path) children.push DirFile.new(self, entry) else children.push DataFile.new(self, entry) end end end |