Class: OpenDAL::Operator
- Inherits:
-
Object
- Object
- OpenDAL::Operator
- Defined in:
- src/operator.rs,
lib/opendal_ruby/operator.rb
Overview
The entrypoint for operating with file services and files.
Instance Method Summary collapse
-
#capability ⇒ Capability
Gets capabilities of the current operator.
-
#copy(from, to) ⇒ nil
Copies a file from
from
toto
. -
#create_dir(path) ⇒ nil
Creates directory recursively similar as
mkdir -p
The ending path must be/
. -
#delete(path) ⇒ nil
Deletes given path.
-
#exist?(path) ⇒ Boolean
Returns if this path exists.
-
#info ⇒ OperatorInfo
Gets meta information of the underlying accessor.
-
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
-
#middleware(middleware) ⇒ Operator
Applies a middleware to the operator.
-
#open(path, mode) ⇒ OpenDAL::IO
Opens a
IO
-like reader for the given path. -
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
-
#remove_all(path) ⇒ nil
Removes the path and all nested directories and files recursively.
-
#rename(from, to) ⇒ nil
Renames a file from
from
toto
. -
#write(path, buffer) ⇒ nil
Writes string into given path.
Instance Method Details
#capability ⇒ Capability
Gets capabilities of the current operator
144 145 146 147 |
# File 'src/operator.rs', line 144
fn capability(&self) -> Result<Capability, Error> {
let capability = self.blocking.info().full_capability();
Ok(Capability::new(capability))
}
|
#copy(from, to) ⇒ nil
Copies a file from from
to to
.
217 218 219 220 221 222 |
# File 'src/operator.rs', line 217
fn copy(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.blocking
.copy(&from, &to)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#create_dir(path) ⇒ nil
Creates directory recursively similar as mkdir -p
The ending path must be /
. Otherwise, OpenDAL throws NotADirectory
error.
155 156 157 158 159 160 |
# File 'src/operator.rs', line 155
fn create_dir(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking
.create_dir(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#delete(path) ⇒ nil
Deletes given path
167 168 169 170 171 172 |
# File 'src/operator.rs', line 167
fn delete(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking
.delete(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#exist?(path) ⇒ Boolean
Returns if this path exists
179 180 181 182 183 184 |
# File 'src/operator.rs', line 179
fn exists(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bool, Error> {
rb_self
.blocking
.exists(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#info ⇒ OperatorInfo
Gets meta information of the underlying accessor.
278 279 280 281 |
# File 'src/operator.rs', line 278
fn info(&self) -> Result<OperatorInfo, Error> {
Ok(OperatorInfo(self.blocking.info()))
}
}
|
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'src/operator.rs', line 243
pub fn list(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Lister, Error> {
let args = scan_args::<(String,), (), (), (), _, ()>(args)?;
let (path,) = args.required;
let kwargs = get_kwargs::<_, (), (Option<usize>, Option<String>, Option<bool>), ()>(
args.keywords,
&[],
&["limit", "start_after", "recursive"],
)?;
let (limit, start_after, recursive) = kwargs.optional;
let mut builder = rb_self.blocking.lister_with(&path);
if let Some(limit) = limit {
builder = builder.limit(limit);
}
if let Some(start_after) = start_after {
builder = builder.start_after(start_after.as_str());
}
if let Some(true) = recursive {
builder = builder.recursive(true);
}
let lister = builder
.call()
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))?;
Ok(Lister::new(lister))
}
|
#middleware(middleware) ⇒ Operator
Applies a middleware to the operator.
25 26 27 |
# File 'lib/opendal_ruby/operator.rb', line 25 def middleware(middleware) middleware.apply_to(self) # duck typing, expects a middleware to implement `#apply_to` end |
#open(path, mode) ⇒ OpenDAL::IO
Opens a IO
-like reader for the given path.
231 232 233 234 |
# File 'src/operator.rs', line 231
fn open(ruby: &Ruby, rb_self: &Self, path: String, mode: String) -> Result<Io, Error> {
let operator = rb_self.blocking.clone();
Io::new(ruby, operator, path, mode)
}
|
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
105 106 107 108 109 110 111 |
# File 'src/operator.rs', line 105
fn read(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bytes::Bytes, Error> {
let buffer = rb_self
.blocking
.read(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))?;
Ok(buffer.to_bytes())
}
|
#remove_all(path) ⇒ nil
Removes the path and all nested directories and files recursively
204 205 206 207 208 209 |
# File 'src/operator.rs', line 204
fn remove_all(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking
.remove_all(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#rename(from, to) ⇒ nil
Renames a file from from
to to
192 193 194 195 196 197 |
# File 'src/operator.rs', line 192
fn rename(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.blocking
.rename(&from, &to)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#write(path, buffer) ⇒ nil
Writes string into given path.
119 120 121 122 123 124 125 |
# File 'src/operator.rs', line 119
fn write(ruby: &Ruby, rb_self: &Self, path: String, bs: RString) -> Result<(), Error> {
rb_self
.blocking
.write(&path, bs.to_bytes())
.map(|_| ())
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|