|
1 | 1 | use magnus::{ |
2 | | - Error, ExceptionClass, Module, RArray, RHash, RModule, RString, Ruby, Value, function, method, |
3 | | - prelude::*, wrap, |
| 2 | + Error, ExceptionClass, Module, RHash, RModule, RString, Ruby, Value, function, method, |
| 3 | + prelude::*, scan_args::scan_args, wrap, |
4 | 4 | }; |
5 | 5 |
|
6 | 6 | #[wrap(class = "URLPattern::URLPattern")] |
7 | 7 | struct UrlPattern(urlpattern::UrlPattern); |
8 | 8 |
|
9 | 9 | impl UrlPattern { |
10 | | - fn new(ruby: &Ruby, arguments: RArray) -> Result<Self, Error> { |
11 | | - let input: Option<Value> = arguments.entry(0)?; |
12 | | - let base_url: Option<Value> = arguments.entry(1)?; |
13 | | - let options: Option<RHash> = arguments.entry(2)?; |
| 10 | + fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, Error> { |
| 11 | + let args = scan_args(args)?; |
| 12 | + let _: () = args.required; |
| 13 | + let (input, base_url, options): (Option<Value>, Option<Value>, Option<RHash>) = |
| 14 | + args.optional; |
| 15 | + let _: () = args.splat; |
| 16 | + let _: () = args.trailing; |
| 17 | + let _: () = args.keywords; |
| 18 | + let _: () = args.block; |
14 | 19 |
|
15 | 20 | let module: RModule = ruby.class_object().const_get("URLPattern")?; |
16 | 21 | let error_class: ExceptionClass = module.const_get("Error")?; |
@@ -87,9 +92,14 @@ impl UrlPattern { |
87 | 92 | )) |
88 | 93 | } |
89 | 94 |
|
90 | | - fn test(ruby: &Ruby, rb_self: &Self, arguments: RArray) -> Result<bool, Error> { |
91 | | - let input: Option<Value> = arguments.entry(0)?; |
92 | | - let base_url: Option<String> = arguments.entry(1)?; |
| 95 | + fn test(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<bool, Error> { |
| 96 | + let args = scan_args(args)?; |
| 97 | + let _: () = args.required; |
| 98 | + let (input, base_url): (Option<Value>, Option<String>) = args.optional; |
| 99 | + let _: () = args.splat; |
| 100 | + let _: () = args.trailing; |
| 101 | + let _: () = args.keywords; |
| 102 | + let _: () = args.block; |
93 | 103 |
|
94 | 104 | let module: RModule = ruby.class_object().const_get("URLPattern")?; |
95 | 105 | let error_class: ExceptionClass = module.const_get("Error")?; |
@@ -148,9 +158,14 @@ impl UrlPattern { |
148 | 158 | .map_err(|e| Error::new(error_class, e.to_string())) |
149 | 159 | } |
150 | 160 |
|
151 | | - fn exec(ruby: &Ruby, rb_self: &Self, arguments: RArray) -> Result<Option<RHash>, Error> { |
152 | | - let input: Option<Value> = arguments.entry(0)?; |
153 | | - let base_url: Option<RString> = arguments.entry(1)?; |
| 161 | + fn exec(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Option<RHash>, Error> { |
| 162 | + let args = scan_args(args)?; |
| 163 | + let _: () = args.required; |
| 164 | + let (input, base_url): (Option<Value>, Option<RString>) = args.optional; |
| 165 | + let _: () = args.splat; |
| 166 | + let _: () = args.trailing; |
| 167 | + let _: () = args.keywords; |
| 168 | + let _: () = args.block; |
154 | 169 |
|
155 | 170 | let module: RModule = ruby.class_object().const_get("URLPattern")?; |
156 | 171 | let error_class: ExceptionClass = module.const_get("Error")?; |
@@ -334,9 +349,9 @@ fn init(ruby: &Ruby) -> Result<(), Error> { |
334 | 349 | let module = ruby.define_module("URLPattern")?; |
335 | 350 | let _error = module.define_error("Error", ruby.exception_standard_error())?; |
336 | 351 | let class = module.define_class("URLPattern", ruby.class_object())?; |
337 | | - class.define_singleton_method("new", function!(UrlPattern::new, -2))?; |
338 | | - class.define_method("test?", method!(UrlPattern::test, -2))?; |
339 | | - class.define_method("exec", method!(UrlPattern::exec, -2))?; |
| 352 | + class.define_singleton_method("new", function!(UrlPattern::new, -1))?; |
| 353 | + class.define_method("test?", method!(UrlPattern::test, -1))?; |
| 354 | + class.define_method("exec", method!(UrlPattern::exec, -1))?; |
340 | 355 | class.define_method("protocol", method!(UrlPattern::protocol, 0))?; |
341 | 356 | class.define_method("username", method!(UrlPattern::username, 0))?; |
342 | 357 | class.define_method("password", method!(UrlPattern::password, 0))?; |
|
0 commit comments