You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "PsiACE (via GitHub)" <gi...@apache.org> on 2023/03/23 10:00:00 UTC

[GitHub] [incubator-opendal] PsiACE opened a new pull request, #1734: feat(bindings/ruby): support read and write

PsiACE opened a new pull request, #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734

   Only the memory case was tested.
   
   If you need to observe `read`, in the previous steps, `pending` needs to be temporarily changed to `pass`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] flaneur2020 commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146124802


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   > I used to see code like the following:
   > 
   > ```ruby
   > require 'async/io'
   > 
   > def echo_server(endpoint)
   >   Async do |task|
   >     # This is a synchronous block within the current task:
   >     endpoint.accept do |client|
   >       # This is an asynchronous block within the current reactor:
   >       data = client.read
   > 
   >       # This produces out-of-order responses.
   >       task.sleep(rand * 0.01)
   > 
   >       client.write(data.reverse)
   >       client.close_write
   >     end
   >   end
   > end
   > ```
   
   unfortunately this is not the standard library but a third party gem, ruby have many possibilities to make magic happen on how the code executes, hard to get how it works for me :(



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146237967


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo merged pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146413023


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,103 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
 
-fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
-    println!("{op:?}")
+use magnus::{class, define_class, error::Result, exception, function, method, prelude::*, Error};
+use opendal as od;
+
+fn build_operator(scheme: od::Scheme, map: HashMap<String, String>) -> Result<od::Operator> {
+    use od::services::*;
+
+    let op = match scheme {
+        od::Scheme::Azblob => od::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Azdfs => od::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Fs => od::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Gcs => od::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Ghac => od::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Http => od::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Ipmfs => od::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Memory => od::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Obs => od::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Oss => od::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::S3 => od::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Webdav => od::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Webhdfs => od::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(od::Error::new(
+                od::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(od::BlockingOperator);
+
+impl Operator {
+    pub fn new(scheme: String, options: Option<HashMap<String, String>>) -> Result<Self> {
+        let scheme = od::Scheme::from_str(&scheme)
+            .map_err(|err| {
+                od::Error::new(od::ErrorKind::Unexpected, "unsupported scheme").set_source(err)
+            })
+            .map_err(format_magnus_error)?;
+        let options = options.unwrap_or_default();
+        Ok(Operator(build_operator(scheme, options)?.blocking()))
+    }
+
+    /// Read the whole path into string.
+    pub fn read(&self, path: String) -> Result<String> {

Review Comment:
   LGTM, now it looks more appropriate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146388386


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,103 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
 
-fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
-    println!("{op:?}")
+use magnus::{class, define_class, error::Result, exception, function, method, prelude::*, Error};
+use opendal as od;
+
+fn build_operator(scheme: od::Scheme, map: HashMap<String, String>) -> Result<od::Operator> {
+    use od::services::*;
+
+    let op = match scheme {
+        od::Scheme::Azblob => od::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Azdfs => od::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Fs => od::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Gcs => od::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Ghac => od::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Http => od::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Ipmfs => od::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Memory => od::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Obs => od::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Oss => od::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::S3 => od::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Webdav => od::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        od::Scheme::Webhdfs => od::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(od::Error::new(
+                od::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(od::BlockingOperator);
+
+impl Operator {
+    pub fn new(scheme: String, options: Option<HashMap<String, String>>) -> Result<Self> {
+        let scheme = od::Scheme::from_str(&scheme)
+            .map_err(|err| {
+                od::Error::new(od::ErrorKind::Unexpected, "unsupported scheme").set_source(err)
+            })
+            .map_err(format_magnus_error)?;
+        let options = options.unwrap_or_default();
+        Ok(Operator(build_operator(scheme, options)?.blocking()))
+    }
+
+    /// Read the whole path into string.
+    pub fn read(&self, path: String) -> Result<String> {

Review Comment:
   I'm guessing we need to return [RString](https://docs.rs/magnus/latest/magnus/r_string/struct.RString.html)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] flaneur2020 commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146113828


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   > Does Ruby have a native bytes type? 
   
   The std library seems favor just use String on representing bytes like:
   
   https://ruby-doc.org/core-2.5.0/IO.html#method-c-read
   
   The string in ruby can contains arbitary characters inside, do not require it must be utf-8 encoded.
   
   > A String object has an arbitrary sequence of bytes, typically representing text or binary data. A String object may be created using [String::new](https://ruby-doc.org/3.2.1/String.html#method-c-new) or as literals.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] flaneur2020 commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146087860


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   I don't think ruby have the builtin await/async style async support, however, we can make api like the callback style:
   
   ```
   operator = AsyncOperator.new
   operator.write("blah") do |resp|
     puts resp.status
   end
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#issuecomment-1480905928

   It seems that implementing Ruby bindings will be relatively simple. I think we can get a preliminary version soon.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1145949859


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   Does Ruby have a native bytes type? The method we demonstrated here does not seem to be the typical approach used by Ruby users.
   
   Take aws ruby s3 sdk as an example:
   
   https://docs.aws.amazon.com/sdk-for-ruby/v1/api/AWS/S3/S3Object.html
   
   ```ruby
   obj.write('Hello World!')
   obj.read
   #=> 'Hello World!'
   ```



##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -15,12 +15,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
+require_relative "../../lib/opendal"
+
 Given("A new OpenDAL Blocking Operator") do
-  pending # Write code here that turns the phrase above into concrete actions
+  @op = Operator.new("memory", nil)
 end
 
 When("Blocking write path {string} with content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.write(string, string2.bytes)

Review Comment:
   Please use more meaningful name like `path` and `content`.



##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   So we will have an `AsyncOperator`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146050183


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   Oh, I's asking about the naming style. How ruby community naming a start which have both blocking and async API?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1145975548


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   I will first support BlockingOperator, and I need to learn more about how to implement asynchronous operations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146050183


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   Oh, Im's asking about the naming style. How ruby community naming a start which have both blocking and async API?



##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   Oh, I'm asking about the naming style. How ruby community naming a start which have both blocking and async API?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146005995


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   I understand what you mean, but like other bindings' implementations, the `read` method here only returns an array. 
   
   I think users may want to process it according to their own needs. Also, my previous writing was not very elegant and simply using `pack(C*)` is sufficient.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146046077


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   > but like other bindings' implementations, the `read` method here only returns an array.
   
   Maybe I should write the guideline down as a document. 
   
   The understanding of bindings' design is wrong. A language binding should be like written by itself. Ruby binding should be like written in ruby and we should follow the common design of the target language itself instead of the rust API or other bindings' API.
   
   Question: If I'm a ruby developer, will I love to use opendal(-ruby)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146142284


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   > in the most of times, I guess a blocking only API is ok in ruby.
   
   Great, let's focus on blocking API first.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] PsiACE commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "PsiACE (via GitHub)" <gi...@apache.org>.
PsiACE commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146253027


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   Now, the `Vec<u8>` in `read` and `write` has been replaced with `String`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146047664


##########
bindings/ruby/tests/steps/binding.rb:
##########
@@ -36,7 +38,7 @@
 end
 
 Then("The blocking file {string} must have content {string}") do |string, string2|
-  pending # Write code here that turns the phrase above into concrete actions
+  @op.read(string).map { |num| num.chr }.join == string2

Review Comment:
   Please always remember our VISION: `Access data freely, painlessly, and efficiently.`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146117990


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {

Review Comment:
   May we remove this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146111426


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   I used to see code like the following:
   
   ```ruby
   require 'async/io'
   
   def echo_server(endpoint)
     Async do |task|
       # This is a synchronous block within the current task:
       endpoint.accept do |client|
         # This is an asynchronous block within the current reactor:
         data = client.read
   
         # This produces out-of-order responses.
         task.sleep(rand * 0.01)
   
         client.write(data.reverse)
         client.close_write
       end
     end
   end
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] flaneur2020 commented on a diff in pull request #1734: feat(bindings/ruby): support read and write

Posted by "flaneur2020 (via GitHub)" <gi...@apache.org>.
flaneur2020 commented on code in PR #1734:
URL: https://github.com/apache/incubator-opendal/pull/1734#discussion_r1146115429


##########
bindings/ruby/src/lib.rs:
##########
@@ -15,16 +15,113 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use magnus::{define_global_function, function, Error};
-use opendal::{services::Memory, Operator};
+use std::{collections::HashMap, str::FromStr};
+
+use magnus::{
+    class, define_class, define_global_function, error::Result, exception, function, method,
+    prelude::*, Error,
+};
+use opendal::services::Memory;
 
 fn hello_opendal() {
-    let op = Operator::new(Memory::default()).unwrap().finish();
+    let op = opendal::Operator::new(Memory::default()).unwrap().finish();
     println!("{op:?}")
 }
 
+fn build_operator(
+    scheme: opendal::Scheme,
+    map: HashMap<String, String>,
+) -> Result<opendal::Operator> {
+    use opendal::services::*;
+
+    let op = match scheme {
+        opendal::Scheme::Azblob => opendal::Operator::from_map::<Azblob>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Azdfs => opendal::Operator::from_map::<Azdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Fs => opendal::Operator::from_map::<Fs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Gcs => opendal::Operator::from_map::<Gcs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ghac => opendal::Operator::from_map::<Ghac>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Http => opendal::Operator::from_map::<Http>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Ipmfs => opendal::Operator::from_map::<Ipmfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Memory => opendal::Operator::from_map::<Memory>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Obs => opendal::Operator::from_map::<Obs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Oss => opendal::Operator::from_map::<Oss>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::S3 => opendal::Operator::from_map::<S3>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webdav => opendal::Operator::from_map::<Webdav>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        opendal::Scheme::Webhdfs => opendal::Operator::from_map::<Webhdfs>(map)
+            .map_err(format_magnus_error)?
+            .finish(),
+        _ => {
+            return Err(format_magnus_error(opendal::Error::new(
+                opendal::ErrorKind::Unexpected,
+                "not supported scheme",
+            )))
+        }
+    };
+
+    Ok(op)
+}
+
+#[magnus::wrap(class = "Operator", free_immediately, size)]
+#[derive(Clone, Debug)]
+pub struct Operator(opendal::BlockingOperator);

Review Comment:
   in the most of times, I guess a blocking only API is ok in ruby.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org