Class: Sfdown::Mapper

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

Overview

Stage 1: walk the directory tree from the root, building the in-memory Node tree. Network only — never touches the filesystem. Sequential for now (concurrency arrives in a later milestone).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, http, parser, log: ->(m) { warn m }) ⇒ Mapper

log: callback for non-fatal diagnostics (defaults to stderr; the CLI routes it through StatusBar#log so the bar stays pinned at the bottom).



282
283
284
285
286
287
288
289
290
291
# File 'lib/sfdown.rb', line 282

def initialize(project, http, parser, log: ->(m) { warn m })
  @project = project
  @http = http
  @parser = parser
  @log = log
  @folders = 0
  @files = 0
  @total_size = 0
  @failures = 0
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures.



278
279
280
# File 'lib/sfdown.rb', line 278

def failures
  @failures
end

#filesObject (readonly)

Returns the value of attribute files.



278
279
280
# File 'lib/sfdown.rb', line 278

def files
  @files
end

#foldersObject (readonly)

Returns the value of attribute folders.



278
279
280
# File 'lib/sfdown.rb', line 278

def folders
  @folders
end

#total_sizeObject (readonly)

Returns the value of attribute total_size.



278
279
280
# File 'lib/sfdown.rb', line 278

def total_size
  @total_size
end

Instance Method Details

#map(&on_page) ⇒ Object

Build and return the synthetic root Node with the whole tree mapped. Yields each directory Node right after its page is parsed (progress hook).



295
296
297
298
299
300
301
302
303
# File 'lib/sfdown.rb', line 295

def map(&on_page)
  @on_page = on_page
  root = Node.new(name: @project, type: :d, path: "", timestamp: nil, size: 0, downloads: 0, children: [])
  walk(root)
  aggregate(root)
  # Root timestamp isn't provided by SF; use the newest child's.
  root.timestamp = root.children.map(&:timestamp).compact.max
  root
end