selma 0.4.14 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- use magnus::{exception, function, scan_args, Error, Module, Object, RModule, Value};
1
+ use magnus::{function, scan_args, Error, Module, Object, RModule, Ruby, Value};
2
2
 
3
3
  #[derive(Clone, Debug)]
4
4
  #[magnus::wrap(class = "Selma::Selector")]
@@ -14,31 +14,30 @@ impl SelmaSelector {
14
14
  fn new(args: &[Value]) -> Result<Self, Error> {
15
15
  let (match_element, match_text_within, rb_ignore_text_within) =
16
16
  Self::scan_parse_args(args)?;
17
+ let ruby = Ruby::get().unwrap();
17
18
 
18
19
  if match_element.is_none() && match_text_within.is_none() {
19
20
  return Err(Error::new(
20
- exception::arg_error(),
21
+ ruby.exception_arg_error(),
21
22
  "Neither `match_element` nor `match_text_within` option given",
22
23
  ));
23
24
  }
24
25
 
25
26
  // FIXME: not excited about this double parse work (`element!` does it too),
26
27
  // but at least we can bail ASAP if the CSS is invalid
27
- if match_element.is_some() {
28
- let css = match_element.as_ref().unwrap();
28
+ if let Some(css) = &match_element {
29
29
  if css.parse::<lol_html::Selector>().is_err() {
30
30
  return Err(Error::new(
31
- exception::arg_error(),
31
+ ruby.exception_arg_error(),
32
32
  format!("Could not parse `match_element` (`{css:?}`) as valid CSS"),
33
33
  ));
34
34
  }
35
35
  }
36
36
 
37
- if match_text_within.is_some() {
38
- let css = match_text_within.as_ref().unwrap();
37
+ if let Some(css) = &match_text_within {
39
38
  if css.parse::<lol_html::Selector>().is_err() {
40
39
  return Err(Error::new(
41
- exception::arg_error(),
40
+ ruby.exception_arg_error(),
42
41
  format!("Could not parse `match_text_within` (`{css:?}`) as valid CSS",),
43
42
  ));
44
43
  }
@@ -102,8 +101,9 @@ impl SelmaSelector {
102
101
  }
103
102
 
104
103
  pub fn init(m_selma: RModule) -> Result<(), Error> {
104
+ let ruby = Ruby::get().unwrap();
105
105
  let c_selector = m_selma
106
- .define_class("Selector", magnus::class::object())
106
+ .define_class("Selector", ruby.class_object())
107
107
  .expect("cannot define class Selma::Selector");
108
108
 
109
109
  c_selector.define_singleton_method("new", function!(SelmaSelector::new, -1))?;
data/lib/selma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Selma
4
- VERSION = "0.4.14"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-12-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rb_sys
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '3.4'
114
114
  requirements: []
115
- rubygems_version: 3.6.2
115
+ rubygems_version: 4.0.6
116
116
  specification_version: 4
117
117
  summary: Selma selects and matches HTML nodes using CSS rules. Backed by Rust's lol_html
118
118
  parser.