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
149 150 151 152 |
# File 'src/operator.rs', line 149
fn capability(&self) -> Result<Capability, Error> {
let capability = self.blocking_op.info().full_capability();
Ok(Capability::new(capability))
}
|
#copy(from, to) ⇒ nil
Copies a file from from
to to
.
222 223 224 225 226 227 |
# File 'src/operator.rs', line 222
fn copy(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.blocking_op
.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.
160 161 162 163 164 165 |
# File 'src/operator.rs', line 160
fn create_dir(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking_op
.create_dir(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#delete(path) ⇒ nil
Deletes given path
172 173 174 175 176 177 |
# File 'src/operator.rs', line 172
fn delete(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking_op
.delete(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#exist?(path) ⇒ Boolean
Returns if this path exists
184 185 186 187 188 189 |
# File 'src/operator.rs', line 184
fn exists(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bool, Error> {
rb_self
.blocking_op
.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_op.info()))
}
}
|
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
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 248
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 lister = rb_self
.blocking_op
.lister_options(
&path,
ocore::options::ListOptions {
limit,
start_after,
recursive: recursive.unwrap_or(false),
..Default::default()
},
)
.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.
236 237 238 239 |
# File 'src/operator.rs', line 236
fn open(ruby: &Ruby, rb_self: &Self, path: String, mode: String) -> Result<Io, Error> {
let operator = rb_self.blocking_op.clone();
Io::new(ruby, operator, path, mode)
}
|
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
110 111 112 113 114 115 116 |
# File 'src/operator.rs', line 110
fn read(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bytes::Bytes, Error> {
let buffer = rb_self
.blocking_op
.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
209 210 211 212 213 214 |
# File 'src/operator.rs', line 209
fn remove_all(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.blocking_op
.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
197 198 199 200 201 202 |
# File 'src/operator.rs', line 197
fn rename(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.blocking_op
.rename(&from, &to)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#write(path, buffer) ⇒ nil
Writes string into given path.
124 125 126 127 128 129 130 |
# File 'src/operator.rs', line 124
fn write(ruby: &Ruby, rb_self: &Self, path: String, bs: RString) -> Result<(), Error> {
rb_self
.blocking_op
.write(&path, bs.to_bytes())
.map(|_| ())
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|