Module: FakeDropbox::Utils

Included in:
Config
Defined in:
lib/fake_dropbox/utils.rb

Constant Summary collapse

DATE_FORMAT =
'%a, %d %b %Y %H:%M:%S %z'

Instance Method Summary collapse

Instance Method Details

#metadata(path, list = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fake_dropbox/utils.rb', line 5

def (path, list=false)
  full_path = File.join(@dropbox_dir, path)
  path.insert(0, '/') if path[0] != '/'
  bytes = File.directory?(path) ? 0 : File.size(full_path)
  
   = {
    thumb_exists: false,
    bytes: bytes,
    modified: File.mtime(full_path).strftime(DATE_FORMAT),
    path: path,
    is_dir: File.directory?(full_path),
    size: "#{bytes} bytes",
    root: "dropbox"
  }
  
  if File.directory?(full_path)
    [:icon] = "folder"
    
    if list
      entries = Dir.entries(full_path).reject { |x| ['.', '..'].include? x }
      [:contents] = entries.map do |entry|
        (File.join(path, entry))
      end
    end
  else
    [:icon] = "page_white"
  end
  
  
end

#safe_path(path) ⇒ Object



36
37
38
# File 'lib/fake_dropbox/utils.rb', line 36

def safe_path(path)
  path.gsub(/(\.\.\/|\/\.\.)/, '')
end

#to_bool(value) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/fake_dropbox/utils.rb', line 40

def to_bool(value)
  return true if value == true || value =~ /(true|t|yes|y|1)$/i
  return false if value == false || value.nil? || value =~ /(false|f|no|n|0)$/i
  raise ArgumentError.new("Invalid value for Boolean: \"#{value}\"")
end