Skip to content

Commit

Permalink
prefactor: clean up Schema.from_document implementations
Browse files Browse the repository at this point in the history
(cherry picked from commit 54b2f6a)
  • Loading branch information
flavorjones committed Jul 5, 2023
1 parent bf38d81 commit 9435007
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ext/java/nokogiri/XmlSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ public class XmlSchema extends RubyObject
public static IRubyObject
from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
{
IRubyObject document = args[0];
IRubyObject rbDocument = args[0];
IRubyObject parseOptions = null;
if (args.length > 1) {
parseOptions = args[1];
}

if (!(document instanceof XmlDocument)) {
if (!(rbDocument instanceof XmlDocument)) {
// TODO: deprecate allowing Node
context.runtime.getWarnings().warn("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
}

XmlDocument doc = ((XmlDocument)((XmlNode) document).document(context));
XmlDocument doc = ((XmlDocument)((XmlNode) rbDocument).document(context));

RubyArray<?> errors = (RubyArray) doc.getInstanceVariable("@errors");
if (!errors.isEmpty()) {
Expand Down
10 changes: 5 additions & 5 deletions ext/nokogiri/xml_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ read_memory(int argc, VALUE *argv, VALUE klass)
* [Returns] Nokogiri::XML::Schema
*/
static VALUE
from_document(int argc, VALUE *argv, VALUE klass)
rb_xml_schema_s_from_document(int argc, VALUE *argv, VALUE klass)
{
VALUE rb_document;
VALUE rb_parse_options;
Expand All @@ -214,14 +214,14 @@ from_document(int argc, VALUE *argv, VALUE klass)

rb_scan_args(argc, argv, "11", &rb_document, &rb_parse_options);

if (rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
c_document = noko_xml_document_unwrap(rb_document);
} else {
if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) {
xmlNodePtr deprecated_node_type_arg;
// TODO: deprecate allowing Node
NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri.");
Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg);
c_document = deprecated_node_type_arg->doc;
} else {
c_document = noko_xml_document_unwrap(rb_document);
}

if (noko_xml_document_has_wrapped_blank_nodes_p(c_document)) {
Expand Down Expand Up @@ -249,7 +249,7 @@ noko_init_xml_schema(void)
rb_undef_alloc_func(cNokogiriXmlSchema);

rb_define_singleton_method(cNokogiriXmlSchema, "read_memory", read_memory, -1);
rb_define_singleton_method(cNokogiriXmlSchema, "from_document", from_document, -1);
rb_define_singleton_method(cNokogiriXmlSchema, "from_document", rb_xml_schema_s_from_document, -1);

rb_define_private_method(cNokogiriXmlSchema, "validate_document", validate_document, 1);
rb_define_private_method(cNokogiriXmlSchema, "validate_file", validate_file, 1);
Expand Down

0 comments on commit 9435007

Please sign in to comment.