class Rstreet::UploadableCollector

Attributes

manifest_builder[R]

TODO: Shouldn’t need to get this for the pull_manifest in rstreet.rb Instead, consider some class method with the default file path info

manifest_uploadable[R]

TODO: Shouldn’t need to get this for the pull_manifest in rstreet.rb Instead, consider some class method with the default file path info

Public Class Methods

new(src) click to toggle source
# File lib/uploadable_collector.rb, line 12
def initialize(src)
  @src = File.realpath src
  # TODO: get rid of cache and consolidate inside of manifest builder
  @uploadables_cache = {}
  init_manifest_builder
end

Public Instance Methods

collect() click to toggle source
# File lib/uploadable_collector.rb, line 19
def collect
  files = FilesReader.read_all(@src)
  uploadables = convert_files_to_uploadables files
  uploadables = add_manifest_to_uploadables uploadables
  save_uploadables_in_manifest uploadables
  uploadables
end
find_uploadables(file_names) click to toggle source

TODO: be more consistent with name, file, path var names

# File lib/uploadable_collector.rb, line 28
def find_uploadables(file_names)
  @uploadables_cache.select { |k, v| file_names.include? k }.values
end

Private Instance Methods

add_manifest_to_uploadables(uploadables) click to toggle source
# File lib/uploadable_collector.rb, line 54
def add_manifest_to_uploadables(uploadables)
  uploadables << @manifest_uploadable if uploadables.any?
  uploadables
end
convert_files_to_uploadables(files) click to toggle source
# File lib/uploadable_collector.rb, line 48
def convert_files_to_uploadables(files)
  files.map do |file|
    convert_to_uploadable(file)
  end
end
convert_to_uploadable(file) click to toggle source
# File lib/uploadable_collector.rb, line 59
def convert_to_uploadable(file)
  Uploadable.new(format_uploadable_name(file), file)
end
ensure_ends_with_separator(path) click to toggle source
# File lib/uploadable_collector.rb, line 67
def ensure_ends_with_separator(path)
  path.end_with?(File::SEPARATOR) ? path : "#{path}#{File::SEPARATOR}"
end
format_uploadable_name(file) click to toggle source
# File lib/uploadable_collector.rb, line 63
def format_uploadable_name(file)
  file.sub(ensure_ends_with_separator(@src), "")
end
init_manifest_builder() click to toggle source
# File lib/uploadable_collector.rb, line 42
def init_manifest_builder
  manifest_file = File.join(@src, ".manifest.json.gz")
  @manifest_uploadable = convert_to_uploadable(manifest_file)
  @manifest_builder = ManifestBuilder.new manifest_file
end
save_uploadables_in_manifest(uploadables) click to toggle source
# File lib/uploadable_collector.rb, line 34
def save_uploadables_in_manifest(uploadables)
  uploadables.each do |u|
    @manifest_builder.add u
    @uploadables_cache[u.name] = u
  end
  @manifest_builder.write
end