Class: WirisPlugin::Store
- Inherits:
-
Object
- Object
- WirisPlugin::Store
- Includes:
- Wiris
- Defined in:
- lib/com/wiris/util/sys/Store.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
- .deleteDirectory(folder, included) ⇒ Object
- .getCurrentPath ⇒ Object
- .newStore(folder) ⇒ Object
- .newStoreWithParent(store, str) ⇒ Object
Instance Method Summary collapse
- #append(str) ⇒ Object
- #copyTo(dest) ⇒ Object
- #delete ⇒ Object
- #deleteFolderContents ⇒ Object
- #exists ⇒ Object
- #getFile ⇒ Object
- #getParent ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #list ⇒ Object
- #mkdirs ⇒ Object
- #moveTo(dest) ⇒ Object
- #read ⇒ Object
- #readBinary ⇒ Object
- #write(str) ⇒ Object
- #writeBinary(bs) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
8 9 10 |
# File 'lib/com/wiris/util/sys/Store.rb', line 8 def initialize() super() end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/com/wiris/util/sys/Store.rb', line 7 def file @file end |
Class Method Details
.deleteDirectory(folder, included) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/com/wiris/util/sys/Store.rb', line 101 def self.deleteDirectory(folder, included) if (folder == nil) || !FileSystem::exists(folder) return end path = FileSystem::fullPath(folder) files = FileSystem::readDirectory(folder) i = 0 for i in 0..files::length - 1 file = files[i] file = (path + '/'.to_s) + file if FileSystem::isDirectory(file) Store.deleteDirectory(file,included) else includedIterator = included::iterator() if included != nil while includedIterator::hasNext() if StringTools::endsWith(file,includedIterator::next()) FileSystem::deleteFile(file) end end else FileSystem::deleteFile(file) end end i+=1 end files = FileSystem::readDirectory(folder) if files::length == 0 FileSystem::deleteDirectory(folder) end end |
.getCurrentPath ⇒ Object
55 56 57 |
# File 'lib/com/wiris/util/sys/Store.rb', line 55 def self.getCurrentPath() return FileSystem::fullPath(".") end |
Instance Method Details
#append(str) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/com/wiris/util/sys/Store.rb', line 37 def append(str) output = File::append(@file,true) output::writeString(str) output::flush() output::close() end |
#copyTo(dest) ⇒ Object
70 71 72 73 |
# File 'lib/com/wiris/util/sys/Store.rb', line 70 def copyTo(dest) b = readBinary() dest::writeBinary(b) end |
#delete ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/com/wiris/util/sys/Store.rb', line 77 def delete() if FileSystem::isDirectory(self.file) FileSystem::deleteDirectory(self.file) else FileSystem::deleteFile(self.file) end end |
#deleteFolderContents ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/com/wiris/util/sys/Store.rb', line 84 def deleteFolderContents() if self.exists() && FileSystem::isDirectory(self.getFile()) files = self.list() for i in 0..files::length - 1 if !((files[i] == ".") || (files[i] == "..")) f = Store::newStoreWithParent(self,files[i]) if FileSystem::isDirectory(f::getFile()) f::deleteFolderContents() FileSystem::deleteDirectory(f::getFile()) else FileSystem::deleteFile(f::getFile()) end end i+=1 end end end |
#exists ⇒ Object
52 53 54 |
# File 'lib/com/wiris/util/sys/Store.rb', line 52 def exists() return FileSystem::exists(@file) end |
#getFile ⇒ Object
49 50 51 |
# File 'lib/com/wiris/util/sys/Store.rb', line 49 def getFile() return @file end |
#getParent ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/com/wiris/util/sys/Store.rb', line 58 def getParent() parent = FileSystem::fullPath(@file) if parent == nil parent = @file end i = WInteger::max(parent::lastIndexOf("/"),parent::lastIndexOf("\\")) if i < 0 return Store.newStore(".") end parent = Std::substr(parent,0,i) return Store.newStore(parent) end |
#list ⇒ Object
16 17 18 |
# File 'lib/com/wiris/util/sys/Store.rb', line 16 def list() return FileSystem::readDirectory(@file) end |
#mkdirs ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/com/wiris/util/sys/Store.rb', line 19 def mkdirs() parent = getParent() if !parent::exists() && !((parent::getFile() == self.file)) parent::mkdirs() end if !exists() FileSystem::createDirectory(@file) end end |
#moveTo(dest) ⇒ Object
74 75 76 |
# File 'lib/com/wiris/util/sys/Store.rb', line 74 def moveTo(dest) FileSystem::rename(self.file,dest::getFile()) end |
#read ⇒ Object
43 44 45 |
# File 'lib/com/wiris/util/sys/Store.rb', line 43 def read() return File::getContent(@file) end |
#readBinary ⇒ Object
34 35 36 |
# File 'lib/com/wiris/util/sys/Store.rb', line 34 def readBinary() return File::getBytes(@file) end |
#write(str) ⇒ Object
28 29 30 |
# File 'lib/com/wiris/util/sys/Store.rb', line 28 def write(str) File::saveContent(@file,str) end |