Class: Cloudpress::Dropbox::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudpress/dropbox/directory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, path, state) ⇒ Directory

Returns a new instance of Directory.



7
8
9
10
11
# File 'lib/cloudpress/dropbox/directory.rb', line 7

def initialize(client, path, state)
  @client      = client
  @path        = path
  @state       = state
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/cloudpress/dropbox/directory.rb', line 5

def client
  @client
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/cloudpress/dropbox/directory.rb', line 5

def path
  @path
end

#stateObject (readonly)

Returns the value of attribute state.



5
6
7
# File 'lib/cloudpress/dropbox/directory.rb', line 5

def state
  @state
end

Instance Method Details

#directory_contentsObject



24
25
26
# File 'lib/cloudpress/dropbox/directory.rb', line 24

def directory_contents
  .with_indifferent_access[:contents]
end

#filesObject



28
29
30
31
32
# File 'lib/cloudpress/dropbox/directory.rb', line 28

def files
  @files ||= directory_contents.select { |x| x[:is_dir] == false }.map do |x| 
    Cloudpress::Dropbox::File.new(x[:path], x[:rev], state)
  end
end

#import!Object



13
14
15
16
# File 'lib/cloudpress/dropbox/directory.rb', line 13

def import!
  files.each { |x| x.import! }
  subdirectories.each {|x| x.import! }
end

#pathsObject



18
19
20
21
22
# File 'lib/cloudpress/dropbox/directory.rb', line 18

def paths
  @paths ||= begin
    files.map {|x| x.path } + subdirectories.map { |x| x.paths }
  end.flatten.compact.uniq
end

#subdirectoriesObject



34
35
36
37
38
# File 'lib/cloudpress/dropbox/directory.rb', line 34

def subdirectories
  @subdirectories ||= directory_contents.select { |x| x[:is_dir] == true }.map do |x|
    Cloudpress::Dropbox::Directory.new(client, x[:path], state)
  end
end