rj_schema 0.0.2 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a67416e1ea1608900c2cb2eaaa4171700b66cc2ba041ff0c3b1238f4987a57b
4
- data.tar.gz: faca49b0027dc70baf288ef5a2895db4515cf4caadbbbdf1be7ecb5f48741bcd
3
+ metadata.gz: 9b4465c406c185df39ae9a8c7cb0d27e6e0e0e5516a060482e6c07aee908ccac
4
+ data.tar.gz: be9ad80bd7a0d1840aa5730e46da6d8a1b839d74df4cab36bc777ec0307bed78
5
5
  SHA512:
6
- metadata.gz: 732c91fc1e727478782f5f8570cb610f03a0f3c7f5b99d08935acb3c887255a853b1dd03e7a74e1c8014a2bf23787569d34978fe27743aa02f6f3a7549506b42
7
- data.tar.gz: d16a2f482a2365dd15aae15240e726a8ffffeb148a56f81e8410cede5ca1fd033c928da902fa1e95b6984b4d078827b47b203086724ffca8ad9955bf252bf346
6
+ metadata.gz: e46aa197637d5b5bb026134b0eadcac0714ad65692b10479d69f93ccf49b10304a4ffdebf42a4925d7f6e9f11a814789f27a9bf48fc75d429e08e77513b2f5a7
7
+ data.tar.gz: fe08e34c5c1e06826109db6779918da9c386f64c6de040ca642749a73481e9c1e3bd70b797600e9a07da9afc52c28a729f6460755cee532a4190e274e7fd26c8
@@ -8,13 +8,13 @@
8
8
  #include <rapidjson/filereadstream.h>
9
9
  #include <rapidjson/prettywriter.h>
10
10
 
11
- typedef std::unordered_map<std::string, rapidjson::SchemaDocument> RemoteSchemaCollection;
11
+ typedef std::unordered_map<std::string, rapidjson::SchemaDocument> SchemaCollection;
12
12
 
13
- class RemoteSchemaDocumentProvider : public rapidjson::IRemoteSchemaDocumentProvider {
14
- RemoteSchemaCollection* schema_collection;
13
+ class SchemaDocumentProvider : public rapidjson::IRemoteSchemaDocumentProvider {
14
+ SchemaCollection* schema_collection;
15
15
 
16
16
  public:
17
- RemoteSchemaDocumentProvider(RemoteSchemaCollection* schema_collection) : schema_collection(schema_collection) { }
17
+ SchemaDocumentProvider(SchemaCollection* schema_collection) : schema_collection(schema_collection) { }
18
18
  virtual const rapidjson::SchemaDocument* GetRemoteDocument(const char* uri, rapidjson::SizeType length) {
19
19
  auto it = schema_collection->find(std::string(uri, length));
20
20
  if (it == schema_collection->end())
@@ -23,10 +23,10 @@ class RemoteSchemaDocumentProvider : public rapidjson::IRemoteSchemaDocumentProv
23
23
  }
24
24
  };
25
25
 
26
- struct RemoteSchemaManager {
27
- RemoteSchemaCollection collection;
28
- RemoteSchemaDocumentProvider provider;
29
- RemoteSchemaManager() : provider(&collection) { }
26
+ struct SchemaManager {
27
+ SchemaCollection collection;
28
+ SchemaDocumentProvider provider;
29
+ SchemaManager() : provider(&collection) { }
30
30
  };
31
31
 
32
32
  rapidjson::Document parse_document(VALUE arg) {
@@ -39,12 +39,9 @@ rapidjson::Document parse_document(VALUE arg) {
39
39
  arg = rb_funcall(arg, rb_intern("to_json"), 0);
40
40
  }
41
41
 
42
- const char* json_document = StringValuePtr(arg);
43
- auto length = RSTRING_LEN(arg);
44
-
45
42
  rapidjson::Document document;
46
43
 
47
- if (document.Parse(json_document, length).HasParseError())
44
+ if (document.Parse(StringValuePtr(arg), RSTRING_LEN(arg)).HasParseError())
48
45
  throw std::invalid_argument("document is not valid JSON");
49
46
 
50
47
  return document;
@@ -52,8 +49,8 @@ rapidjson::Document parse_document(VALUE arg) {
52
49
 
53
50
  VALUE perform_validation(VALUE self, VALUE schema_arg, VALUE document_arg, bool with_errors) {
54
51
  try {
55
- RemoteSchemaManager* schema_manager;
56
- Data_Get_Struct(self, RemoteSchemaManager, schema_manager);
52
+ SchemaManager* schema_manager;
53
+ Data_Get_Struct(self, SchemaManager, schema_manager);
57
54
  auto document = parse_document(document_arg);
58
55
  auto validate = [with_errors, &document](const rapidjson::SchemaDocument& schema) -> VALUE {
59
56
  rapidjson::SchemaValidator validator(schema);
@@ -103,17 +100,17 @@ extern "C" VALUE validator_valid(VALUE self, VALUE schema_arg, VALUE document_ar
103
100
  return perform_validation(self, schema_arg, document_arg, false);
104
101
  }
105
102
 
106
- extern "C" void validator_free(RemoteSchemaManager* schema_manager) {
103
+ extern "C" void validator_free(SchemaManager* schema_manager) {
107
104
  delete schema_manager;
108
105
  }
109
106
 
110
107
  extern "C" VALUE validator_alloc(VALUE self) {
111
- auto* schema_manager = new RemoteSchemaManager;
108
+ auto* schema_manager = new SchemaManager;
112
109
  return Data_Wrap_Struct(self, NULL, validator_free, schema_manager);
113
110
  }
114
111
 
115
112
  extern "C" int validator_initialize_load_schema(VALUE key, VALUE value, VALUE input) {
116
- auto* schema_manager = reinterpret_cast<RemoteSchemaManager*>(input);
113
+ auto* schema_manager = reinterpret_cast<SchemaManager*>(input);
117
114
 
118
115
  try {
119
116
  schema_manager->collection.emplace(
@@ -137,8 +134,8 @@ extern "C" VALUE validator_initialize(int argc, VALUE* argv, VALUE self) {
137
134
  if (argc == 0)
138
135
  return self;
139
136
 
140
- RemoteSchemaManager* schema_manager;
141
- Data_Get_Struct(self, RemoteSchemaManager, schema_manager);
137
+ SchemaManager* schema_manager;
138
+ Data_Get_Struct(self, SchemaManager, schema_manager);
142
139
 
143
140
  rb_hash_foreach(argv[0], reinterpret_cast<int(*)(...)>(validator_initialize_load_schema), reinterpret_cast<VALUE>(schema_manager));
144
141
 
data/lib/rj_schema.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  class RjSchema
4
- VERSION = '0.0.2'
4
+ VERSION = '0.1.0'
5
5
  end
6
6
 
7
7
  require 'rj_schema/rj_schema'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rj_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Semmler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2018-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler