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
fromtoto. -
#create_dir(path) ⇒ nil
Creates directory recursively similar as
mkdir -pThe 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
fromtoto. -
#write(path, buffer) ⇒ nil
Writes string into given path.
Instance Method Details
#capability ⇒ Capability
Gets capabilities of the current operator
142 143 144 145 |
# File 'src/operator.rs', line 142
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.
153 154 155 156 157 158 |
# File 'src/operator.rs', line 153
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
165 166 167 168 169 170 |
# File 'src/operator.rs', line 165
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
177 178 179 180 181 182 |
# File 'src/operator.rs', line 177
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.
287 288 289 290 |
# File 'src/operator.rs', line 287
fn info(&self) -> Result<OperatorInfo, Error> {
Ok(OperatorInfo(self.blocking_op.info()))
}
}
|
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'src/operator.rs', line 257
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 240 241 242 243 244 245 246 247 248 |
# File 'src/operator.rs', line 236
fn open(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Io, Error> {
let args = scan_args::<(String,), (Option<Value>, Option<Value>), (), (), RHash, ()>(args)?;
let (path,) = args.required;
let (option_mode, option_permission) = args.optional;
let kwargs = args.keywords;
// Ruby handles Qnil safely (will not assign to Qnil)
let mode = option_mode.unwrap_or(ruby.str_new("r").as_value());
let permission = option_permission.unwrap_or(ruby.qnil().as_value());
let operator = rb_self.blocking_op.clone();
Io::new(ruby, operator, path, mode, permission, kwargs)
}
|
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
103 104 105 106 107 108 109 |
# File 'src/operator.rs', line 103
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
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'src/operator.rs', line 202
fn remove_all(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
use ocore::options::DeleteOptions;
rb_self
.blocking_op
.delete_options(
&path,
DeleteOptions {
recursive: true,
..Default::default()
},
)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#rename(from, to) ⇒ nil
Renames a file from from to to
190 191 192 193 194 195 |
# File 'src/operator.rs', line 190
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.
117 118 119 120 121 122 123 |
# File 'src/operator.rs', line 117
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()))
}
|