|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#![allow( |
| 19 | + rustdoc::broken_intra_doc_links, |
| 20 | + reason = "YARD's syntax for documentation" |
| 21 | +)] |
| 22 | + |
| 23 | +use magnus::class; |
| 24 | +use magnus::method; |
| 25 | +use magnus::prelude::*; |
| 26 | +use magnus::Error; |
| 27 | +use magnus::RModule; |
| 28 | + |
| 29 | +use crate::capability::Capability; |
| 30 | +use crate::*; |
| 31 | + |
| 32 | +/// Metadata for operator, users can use this metadata to get information of operator. |
| 33 | +#[magnus::wrap(class = "OpenDAL::OperatorInfo", free_immediately, size)] |
| 34 | +pub struct OperatorInfo(pub ocore::OperatorInfo); |
| 35 | + |
| 36 | +impl OperatorInfo { |
| 37 | + /// @yard |
| 38 | + /// @def scheme |
| 39 | + /// Returns the scheme string of the operator. |
| 40 | + /// @return [String] |
| 41 | + pub fn scheme(&self) -> &str { |
| 42 | + self.0.scheme().into() |
| 43 | + } |
| 44 | + |
| 45 | + /// @yard |
| 46 | + /// @def root |
| 47 | + /// Returns the root path of the operator, will be in format like `/path/to/dir/` |
| 48 | + /// @return [String] |
| 49 | + pub fn root(&self) -> String { |
| 50 | + self.0.root() |
| 51 | + } |
| 52 | + |
| 53 | + /// @yard |
| 54 | + /// @def name |
| 55 | + /// Returns the name of backend, could be empty if underlying backend doesn't have namespace concept. |
| 56 | + /// |
| 57 | + /// For example: |
| 58 | + /// |
| 59 | + /// - name for `s3` => bucket name |
| 60 | + /// - name for `azblob` => container name |
| 61 | + /// |
| 62 | + /// @return [String] |
| 63 | + pub fn name(&self) -> String { |
| 64 | + self.0.name() |
| 65 | + } |
| 66 | + |
| 67 | + /// @yard |
| 68 | + /// @def capability |
| 69 | + /// Returns the [`Full Capability`] of the operator. |
| 70 | + /// @return [Capability] |
| 71 | + pub fn capability(&self) -> Capability { |
| 72 | + Capability::new(self.0.full_capability()) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +pub fn include(gem_module: &RModule) -> Result<(), Error> { |
| 77 | + let class = gem_module.define_class("OperatorInfo", class::object())?; |
| 78 | + class.define_method("scheme", method!(OperatorInfo::scheme, 0))?; |
| 79 | + class.define_method("root", method!(OperatorInfo::root, 0))?; |
| 80 | + class.define_method("name", method!(OperatorInfo::name, 0))?; |
| 81 | + class.define_method("capability", method!(OperatorInfo::capability, 0))?; |
| 82 | + |
| 83 | + Ok(()) |
| 84 | +} |
0 commit comments