rsmp_schema 0.2.5 → 0.3.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: da6aa7917da1551ed490189b8b6d782c9ae6c6d4baf4b46adabcc21cc801cc19
4
- data.tar.gz: a916a1d6fbc64fcdc050f1be7a4d6c2a603497c54e73baa58c7d775c8c39c803
3
+ metadata.gz: 575a89e29f57a294f101abea73f59c22c43d4156ad3b700f5c71bbda7dcbe79b
4
+ data.tar.gz: 2887c0c2f4ccb51ae60f41dfd499035d136317fd5086255c14f26a255d26b365
5
5
  SHA512:
6
- metadata.gz: 675151863b4bbbffa9d6598e833dcda25d48cf0ce332c9ce05e035fe7f6567269e1b180032182335eeeaf2ae915fc78a75478116f21fcfa496809cffdbeeaf49
7
- data.tar.gz: baf90db70f6950c2a7c20bec201d4b347fd478e5716f71fdef263db690edf8423df45ad0531fef3a26b8ade57eec0eacfb3ac1004dde88420f197a9740345285
6
+ metadata.gz: 02b3e8b39f2eb04775a6c723bb9b6cffd5e2ab66e987ee77b16c5cfb895a47cf201c1efc557f0a2b90b7e035b8483905f08624999643bcaf823c1614dbefbceb
7
+ data.tar.gz: 99df31b79fe0b7f74f60b441d47d43ad6e8a2ca756907ec0d5f9a61783e5bb3ce4016aa448a731c5825714ea6eae4e62a0fe5e8c9cd684c1ffcce8796c4cb14a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp_schema (0.2.5)
4
+ rsmp_schema (0.3.0)
5
5
  json_schemer (~> 0.2.21)
6
6
  thor (~> 1.2.1)
7
7
 
data/README.md CHANGED
@@ -13,14 +13,14 @@ The schema consists of a core schema shared by all equipment types, and an SXL s
13
13
 
14
14
  Both core and SXL schemas exist in different version, for validation agaist a particular version of the spec.
15
15
 
16
- For example, to validate against the SXL for Trafic Light Controllers (TLCs), version 1.0.15, use the file schemas/tcl/1.0.15/sxl.json.
16
+ For example, to validate against the SXL for Trafic Light Controllers (TLCs), version 1.0.15, use the file schemas/tcl/1.0.15/rsmp.json.
17
17
 
18
18
  Depending on the message type, relevant JSON Schema elements will be included to validate the detailed parameters, arguments, etc.
19
19
 
20
20
  For example, validating a CommandRequest M0001 message will include these parts:
21
21
 
22
22
  ```
23
- sxl.json
23
+ rsmp.json
24
24
  commands.json
25
25
  M0001.json
26
26
  ```
@@ -52,7 +52,7 @@ message = {
52
52
  }
53
53
 
54
54
  # try validating a message against our schema
55
- schema = Pathname.new('schemas/tlc/1.1/sxl.json')
55
+ schema = Pathname.new('schemas/tlc/1.1/rsmp.json')
56
56
  schemer = JSONSchemer.schema(schema)
57
57
  puts schemer.valid? message # => true
58
58
  ```
data/examples/validate.rb CHANGED
@@ -19,7 +19,7 @@ message = {
19
19
  }
20
20
 
21
21
  # try validating a message against our schema
22
- schema = Pathname.new('schema/tlc/sxl.json')
22
+ schema = Pathname.new('schema/tlc/1.1/rsmp.json')
23
23
  schemer = JSONSchemer.schema(schema)
24
24
  if schemer.valid? message
25
25
  puts 'ok'
@@ -242,7 +242,7 @@ module RSMP
242
242
  }
243
243
  ]
244
244
  }
245
- out["sxl.json"] = output_json json
245
+ out["rsmp.json"] = output_json json
246
246
  end
247
247
 
248
248
  # generate the json schema from a string containing yaml
@@ -11,21 +11,41 @@ module RSMP::Schema
11
11
  schemas_path = File.expand_path( File.join(__dir__,'..','..','schemas') )
12
12
  Dir.glob("#{schemas_path}/*").select {|f| File.directory? f}.each do |type_path|
13
13
  type = File.basename(type_path).to_sym
14
- @@schemas[type] = {}
15
- Dir.glob("#{type_path}/*").select {|f| File.directory? f}.each do |schema_path|
16
- version = File.basename(schema_path)
17
- if type == :core
18
- file = 'rsmp.json'
19
- else
20
- file = 'sxl.json'
21
- end
22
- @@schemas[type][version] = JSONSchemer.schema(
23
- Pathname.new(File.join(schema_path,file))
24
- )
25
- end
14
+ load_schema_type type, type_path
15
+ end
16
+ end
17
+
18
+ # load an schema from a folder. schemas are organized by version, and contain
19
+ # json schema files, with the entry point being rsmp.jspon, eg:
20
+ # tlc
21
+ # 1.0.7
22
+ # rsmp.json
23
+ # other jon schema files...
24
+ # 1.0.8
25
+ # ...
26
+ #
27
+ # an error is raised if the schema type already exists, and force is not set to true
28
+ def self.load_schema_type type, type_path, force:false
29
+ raise RuntimeError.new("Schema type #{type} already loaded") if @@schemas[type] && force!=true
30
+ @@schemas[type] = {}
31
+ Dir.glob("#{type_path}/*").select {|f| File.directory? f}.each do |schema_path|
32
+ version = File.basename(schema_path)
33
+ @@schemas[type][version] = JSONSchemer.schema(
34
+ Pathname.new(File.join(schema_path,'rsmp.json'))
35
+ )
26
36
  end
27
37
  end
28
38
 
39
+ # remove a schema type
40
+ def self.remove_schema_type type
41
+ schemas.delete type
42
+ end
43
+
44
+ # get schemas types
45
+ def self.schema_types
46
+ schemas.keys
47
+ end
48
+
29
49
  # get all schemas, oganized by type and version
30
50
  def self.schemas
31
51
  raise RuntimeError.new("No schemas available, perhaps Schema.setup was never called?") unless @@schemas
@@ -1,5 +1,5 @@
1
1
  module RSMP
2
2
  module Schema
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-26 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_schemer
@@ -190,6 +190,7 @@ files:
190
190
  - schemas/tlc/1.0.10/commands/command_requests.json
191
191
  - schemas/tlc/1.0.10/commands/command_responses.json
192
192
  - schemas/tlc/1.0.10/commands/commands.json
193
+ - schemas/tlc/1.0.10/rsmp.json
193
194
  - schemas/tlc/1.0.10/statuses/S0001.json
194
195
  - schemas/tlc/1.0.10/statuses/S0002.json
195
196
  - schemas/tlc/1.0.10/statuses/S0003.json
@@ -220,7 +221,6 @@ files:
220
221
  - schemas/tlc/1.0.10/statuses/S0203.json
221
222
  - schemas/tlc/1.0.10/statuses/S0204.json
222
223
  - schemas/tlc/1.0.10/statuses/statuses.json
223
- - schemas/tlc/1.0.10/sxl.json
224
224
  - schemas/tlc/1.0.10/sxl.yaml
225
225
  - schemas/tlc/1.0.13/alarms/A0001.json
226
226
  - schemas/tlc/1.0.13/alarms/A0002.json
@@ -260,6 +260,7 @@ files:
260
260
  - schemas/tlc/1.0.13/commands/command_requests.json
261
261
  - schemas/tlc/1.0.13/commands/command_responses.json
262
262
  - schemas/tlc/1.0.13/commands/commands.json
263
+ - schemas/tlc/1.0.13/rsmp.json
263
264
  - schemas/tlc/1.0.13/statuses/S0001.json
264
265
  - schemas/tlc/1.0.13/statuses/S0002.json
265
266
  - schemas/tlc/1.0.13/statuses/S0003.json
@@ -298,7 +299,6 @@ files:
298
299
  - schemas/tlc/1.0.13/statuses/S0203.json
299
300
  - schemas/tlc/1.0.13/statuses/S0204.json
300
301
  - schemas/tlc/1.0.13/statuses/statuses.json
301
- - schemas/tlc/1.0.13/sxl.json
302
302
  - schemas/tlc/1.0.13/sxl.yaml
303
303
  - schemas/tlc/1.0.14/alarms/A0001.json
304
304
  - schemas/tlc/1.0.14/alarms/A0002.json
@@ -338,6 +338,7 @@ files:
338
338
  - schemas/tlc/1.0.14/commands/command_requests.json
339
339
  - schemas/tlc/1.0.14/commands/command_responses.json
340
340
  - schemas/tlc/1.0.14/commands/commands.json
341
+ - schemas/tlc/1.0.14/rsmp.json
341
342
  - schemas/tlc/1.0.14/statuses/S0001.json
342
343
  - schemas/tlc/1.0.14/statuses/S0002.json
343
344
  - schemas/tlc/1.0.14/statuses/S0003.json
@@ -380,7 +381,6 @@ files:
380
381
  - schemas/tlc/1.0.14/statuses/S0207.json
381
382
  - schemas/tlc/1.0.14/statuses/S0208.json
382
383
  - schemas/tlc/1.0.14/statuses/statuses.json
383
- - schemas/tlc/1.0.14/sxl.json
384
384
  - schemas/tlc/1.0.14/sxl.yaml
385
385
  - schemas/tlc/1.0.15/alarms/A0001.json
386
386
  - schemas/tlc/1.0.15/alarms/A0002.json
@@ -423,6 +423,7 @@ files:
423
423
  - schemas/tlc/1.0.15/commands/command_requests.json
424
424
  - schemas/tlc/1.0.15/commands/command_responses.json
425
425
  - schemas/tlc/1.0.15/commands/commands.json
426
+ - schemas/tlc/1.0.15/rsmp.json
426
427
  - schemas/tlc/1.0.15/statuses/S0001.json
427
428
  - schemas/tlc/1.0.15/statuses/S0002.json
428
429
  - schemas/tlc/1.0.15/statuses/S0003.json
@@ -469,7 +470,6 @@ files:
469
470
  - schemas/tlc/1.0.15/statuses/S0207.json
470
471
  - schemas/tlc/1.0.15/statuses/S0208.json
471
472
  - schemas/tlc/1.0.15/statuses/statuses.json
472
- - schemas/tlc/1.0.15/sxl.json
473
473
  - schemas/tlc/1.0.15/sxl.yaml
474
474
  - schemas/tlc/1.0.7/alarms/A0001.json
475
475
  - schemas/tlc/1.0.7/alarms/A0002.json
@@ -502,6 +502,7 @@ files:
502
502
  - schemas/tlc/1.0.7/commands/command_requests.json
503
503
  - schemas/tlc/1.0.7/commands/command_responses.json
504
504
  - schemas/tlc/1.0.7/commands/commands.json
505
+ - schemas/tlc/1.0.7/rsmp.json
505
506
  - schemas/tlc/1.0.7/statuses/S0001.json
506
507
  - schemas/tlc/1.0.7/statuses/S0002.json
507
508
  - schemas/tlc/1.0.7/statuses/S0003.json
@@ -533,7 +534,6 @@ files:
533
534
  - schemas/tlc/1.0.7/statuses/S0203.json
534
535
  - schemas/tlc/1.0.7/statuses/S0204.json
535
536
  - schemas/tlc/1.0.7/statuses/statuses.json
536
- - schemas/tlc/1.0.7/sxl.json
537
537
  - schemas/tlc/1.0.7/sxl.yaml
538
538
  - schemas/tlc/1.0.8/alarms/A0001.json
539
539
  - schemas/tlc/1.0.8/alarms/A0002.json
@@ -568,6 +568,7 @@ files:
568
568
  - schemas/tlc/1.0.8/commands/command_requests.json
569
569
  - schemas/tlc/1.0.8/commands/command_responses.json
570
570
  - schemas/tlc/1.0.8/commands/commands.json
571
+ - schemas/tlc/1.0.8/rsmp.json
571
572
  - schemas/tlc/1.0.8/statuses/S0001.json
572
573
  - schemas/tlc/1.0.8/statuses/S0002.json
573
574
  - schemas/tlc/1.0.8/statuses/S0003.json
@@ -599,7 +600,6 @@ files:
599
600
  - schemas/tlc/1.0.8/statuses/S0203.json
600
601
  - schemas/tlc/1.0.8/statuses/S0204.json
601
602
  - schemas/tlc/1.0.8/statuses/statuses.json
602
- - schemas/tlc/1.0.8/sxl.json
603
603
  - schemas/tlc/1.0.8/sxl.yaml
604
604
  - schemas/tlc/1.0.9/alarms/A0001.json
605
605
  - schemas/tlc/1.0.9/alarms/A0002.json
@@ -634,6 +634,7 @@ files:
634
634
  - schemas/tlc/1.0.9/commands/command_requests.json
635
635
  - schemas/tlc/1.0.9/commands/command_responses.json
636
636
  - schemas/tlc/1.0.9/commands/commands.json
637
+ - schemas/tlc/1.0.9/rsmp.json
637
638
  - schemas/tlc/1.0.9/statuses/S0001.json
638
639
  - schemas/tlc/1.0.9/statuses/S0002.json
639
640
  - schemas/tlc/1.0.9/statuses/S0003.json
@@ -665,7 +666,6 @@ files:
665
666
  - schemas/tlc/1.0.9/statuses/S0203.json
666
667
  - schemas/tlc/1.0.9/statuses/S0204.json
667
668
  - schemas/tlc/1.0.9/statuses/statuses.json
668
- - schemas/tlc/1.0.9/sxl.json
669
669
  - schemas/tlc/1.0.9/sxl.yaml
670
670
  - schemas/tlc/1.1/alarms/A0001.json
671
671
  - schemas/tlc/1.1/alarms/A0002.json
@@ -712,6 +712,7 @@ files:
712
712
  - schemas/tlc/1.1/commands/command_requests.json
713
713
  - schemas/tlc/1.1/commands/command_responses.json
714
714
  - schemas/tlc/1.1/commands/commands.json
715
+ - schemas/tlc/1.1/rsmp.json
715
716
  - schemas/tlc/1.1/statuses/S0001.json
716
717
  - schemas/tlc/1.1/statuses/S0002.json
717
718
  - schemas/tlc/1.1/statuses/S0003.json
@@ -761,7 +762,6 @@ files:
761
762
  - schemas/tlc/1.1/statuses/S0207.json
762
763
  - schemas/tlc/1.1/statuses/S0208.json
763
764
  - schemas/tlc/1.1/statuses/statuses.json
764
- - schemas/tlc/1.1/sxl.json
765
765
  - schemas/tlc/1.1/sxl.yaml
766
766
  homepage: https://github.com/rsmp-nordic/rsmp_schema
767
767
  licenses: