Class: DropboximusPrime

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

Defined Under Namespace

Classes: DPImage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ DropboximusPrime

Returns a new instance of DropboximusPrime.



12
13
14
15
16
# File 'lib/dropboximus_prime.rb', line 12

def initialize arg=nil
  @settings = init_settings(arg)
  @dropbox = init_dropbox
  @markdown = init_markdown
end

Instance Attribute Details

#dropboxObject

Returns the value of attribute dropbox.



10
11
12
# File 'lib/dropboximus_prime.rb', line 10

def dropbox
  @dropbox
end

#markdownObject

Returns the value of attribute markdown.



10
11
12
# File 'lib/dropboximus_prime.rb', line 10

def markdown
  @markdown
end

#settingsObject

Returns the value of attribute settings.



10
11
12
# File 'lib/dropboximus_prime.rb', line 10

def settings
  @settings
end

Instance Method Details

#get(*items) ⇒ Object



18
19
20
21
22
# File 'lib/dropboximus_prime.rb', line 18

def get *items
  aggregate_paths(items).each_with_object({}) { |key, memo|
    memo[key] = get_item(cache_path(key))
  }
end

#get_one(item) ⇒ Object



24
25
26
# File 'lib/dropboximus_prime.rb', line 24

def get_one item
  get(item).values[0]
end

#prune!Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dropboximus_prime.rb', line 42

def prune!
  local_files = aggregate_paths(['**/*'])
  local_dirs = dirs_only(local_files)

  remote_files = dropbox_list_files_recursively(@settings['dropbox']['path']).each_with_object([]) { |x, memo|
    memo.push remote_path_to_relative_path(x)
  }
  remote_dirs = dropbox_list_dirs_recursively(@settings['dropbox']['path']).each_with_object([]) { |x, memo|
    memo.push remote_path_to_relative_path(x)
  }

  orphan_files = local_files.each_with_object([]) { |x, memo|
    memo.push x unless remote_files.include? x
  }
  orphan_dirs = local_dirs.each_with_object([]) { |x, memo|
    memo.push x unless remote_dirs.include? x
  }

  orphan_files.each { |x|
    FileUtils.rm(cache_path(x), force: true)
  }
  orphan_dirs.each { |x|
    FileUtils.rm(cache_path(x), force: true)
  }
end

#refresh(*items) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dropboximus_prime.rb', line 28

def refresh *items
  if items.length > 0
    local_paths = aggregate_paths(items)
  else
    local_paths = dropbox_list_files_recursively(@settings['dropbox']['path']).map! { |item|
      remote_path_to_relative_path item
    }
  end

  local_paths.each { |item|
    refresh_item(item)
  }
end