Skip to content

Commit 70f90bd

Browse files
committed
Ensure exception classes defined on-load in Rust
1 parent 32d480a commit 70f90bd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ext/rust_json_schema/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,9 @@ fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
9797
class.define_method("valid?", method!(Validator::is_valid, 1))?;
9898
class.define_method("validate", method!(Validator::validate, 1))?;
9999

100+
// Ensure defined at load time
101+
Lazy::force(&JSON_PARSE_ERROR, ruby);
102+
Lazy::force(&SCHEMA_PARSE_ERROR, ruby);
103+
100104
Ok(())
101105
}

lib/rust_json_schema.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
require_relative "rust_json_schema/version"
44

5-
# Tries to require the extension for the given Ruby version first
6-
begin
7-
RUBY_VERSION =~ /(\d+\.\d+)/
8-
require "rust_json_schema/#{Regexp.last_match(1)}/rust_json_schema"
9-
rescue LoadError
10-
require_relative "rust_json_schema/rust_json_schema"
11-
end
12-
135
module RustJSONSchema
146
class Error < StandardError; end
157

168
class JSONParseError < Error; end
179

1810
class SchemaParseError < Error; end
1911
end
12+
13+
# Tries to require the extension for the given Ruby version first
14+
begin
15+
RUBY_VERSION =~ /(\d+\.\d+)/
16+
require "rust_json_schema/#{Regexp.last_match(1)}/rust_json_schema"
17+
rescue LoadError
18+
require_relative "rust_json_schema/rust_json_schema"
19+
end

0 commit comments

Comments
 (0)