You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/03/24 07:03:54 UTC
[incubator-opendal] branch main updated: feat(bindings/ruby): add namespace (#1745)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 593c031b feat(bindings/ruby): add namespace (#1745)
593c031b is described below
commit 593c031b7dbe389ffd999a31ad6b34fe0f80c980
Author: Chojan Shang <ps...@apache.org>
AuthorDate: Fri Mar 24 15:03:48 2023 +0800
feat(bindings/ruby): add namespace (#1745)
Signed-off-by: Chojan Shang <ps...@outlook.com>
---
bindings/ruby/src/lib.rs | 11 ++++++-----
bindings/ruby/tests/steps/binding.rb | 2 +-
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/bindings/ruby/src/lib.rs b/bindings/ruby/src/lib.rs
index 9af13fed..8e5fc7a2 100644
--- a/bindings/ruby/src/lib.rs
+++ b/bindings/ruby/src/lib.rs
@@ -18,7 +18,7 @@
use std::{collections::HashMap, str::FromStr};
use magnus::{
- class, define_class, error::Result, exception, function, method, prelude::*, Error, RString,
+ class, define_module, error::Result, exception, function, method, prelude::*, Error, RString,
};
use opendal as od;
@@ -76,7 +76,7 @@ fn build_operator(scheme: od::Scheme, map: HashMap<String, String>) -> Result<od
Ok(op)
}
-#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[magnus::wrap(class = "OpenDAL::Operator", free_immediately, size)]
#[derive(Clone, Debug)]
pub struct Operator(od::BlockingOperator);
@@ -113,7 +113,7 @@ impl Operator {
}
}
-#[magnus::wrap(class = "Metadata", free_immediately, size)]
+#[magnus::wrap(class = "OpenDAL::Metadata", free_immediately, size)]
pub struct Metadata(od::Metadata);
impl Metadata {
@@ -159,13 +159,14 @@ fn format_magnus_error(err: od::Error) -> Error {
#[magnus::init]
fn init() -> Result<()> {
- let operator_class = define_class("Operator", class::object())?;
+ let namespace = define_module("OpenDAL")?;
+ let operator_class = namespace.define_class("Operator", class::object())?;
operator_class.define_singleton_method("new", function!(Operator::new, 2))?;
operator_class.define_method("read", method!(Operator::read, 1))?;
operator_class.define_method("write", method!(Operator::write, 2))?;
operator_class.define_method("stat", method!(Operator::stat, 1))?;
- let metadata_class = define_class("Metadata", class::object())?;
+ let metadata_class = namespace.define_class("Metadata", class::object())?;
metadata_class.define_method(
"content_disposition",
method!(Metadata::content_disposition, 0),
diff --git a/bindings/ruby/tests/steps/binding.rb b/bindings/ruby/tests/steps/binding.rb
index 1607b2f7..948dae51 100644
--- a/bindings/ruby/tests/steps/binding.rb
+++ b/bindings/ruby/tests/steps/binding.rb
@@ -18,7 +18,7 @@
require_relative "../../lib/opendal"
Given("A new OpenDAL Blocking Operator") do
- @op = Operator.new("memory", nil)
+ @op = OpenDAL::Operator.new("memory", nil)
end
When("Blocking write path {string} with content {string}") do |path, content|