Class: GDSync::LocalFileSystem::Dir

Inherits:
AbstractDir
  • Object
show all
Defined in:
lib/file_system/local_file_system.rb

Instance Method Summary collapse

Constructor Details

#initialize(fs, path) ⇒ Dir

Returns a new instance of Dir


88
89
90
91
# File 'lib/file_system/local_file_system.rb', line 88

def initialize(fs, path)
  @fs = fs
  @path = path
end

Instance Method Details

#create_dir!(_title) ⇒ Object


120
121
122
123
124
# File 'lib/file_system/local_file_system.rb', line 120

def create_dir!(_title)
  newpath = ::File.join(@path, _title)
  ::Dir.mkdir(newpath)
  Dir.new(@fs, newpath)
end

#create_file_with_read_io!(_io, _title, _mtime, _birthtime) ⇒ Object


126
127
128
129
130
131
132
133
# File 'lib/file_system/local_file_system.rb', line 126

def create_file_with_read_io!(_io, _title, _mtime, _birthtime)
  newfile = ::File.join(@path, _title)
  open(newfile, 'wb') { |f|
    IO.copy_stream(_io, f)
  }
  ::File.utime(_mtime, _mtime, newfile)
  File.new(@fs, newfile)
end

#create_write_io!(_title) ⇒ Object


135
136
137
138
139
140
# File 'lib/file_system/local_file_system.rb', line 135

def create_write_io!(_title)
  newfile = ::File.join(@path, _title)
  io = open(newfile, 'wb')
  file = File.new(@fs, newfile)
  return file, io
end

#delete!Object


142
143
144
# File 'lib/file_system/local_file_system.rb', line 142

def delete!
  ::FileUtils.rm_r(@path)
end

#entries(&block) ⇒ Object


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/file_system/local_file_system.rb', line 97

def entries(&block)
  entries = ::Dir.entries(@path, :encoding => ::Encoding::UTF_8)
  entries.select { |e|
    e != '.' and e != '..'
  }.each { |e|
    path = ::File.join(@path, e)

    next if ::Gem.win_platform? && ::File.hidden?(path)

    f = nil
    if ::File.directory?(path)
      f = Dir.new(@fs, path)
    else
      f = File.new(@fs, path)
    end
    block.call(f)
  }
end

#fsObject


116
117
118
# File 'lib/file_system/local_file_system.rb', line 116

def fs
  @fs
end

#pathObject


146
147
148
# File 'lib/file_system/local_file_system.rb', line 146

def path
  @path
end

#titleObject


93
94
95
# File 'lib/file_system/local_file_system.rb', line 93

def title
  ::File.basename(@path)
end