jcrvalidator 0.7.0 → 0.8.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
  SHA1:
3
- metadata.gz: 1092c1613500ed477ee3eb26367ed73fee3a940f
4
- data.tar.gz: 824cdfcc22c6dc6a03d55bc10ad75857c881c627
3
+ metadata.gz: 61807efb31326c093b5f71984a9ee55e41710598
4
+ data.tar.gz: d6184f8217ff27d09729397af1a43a493d972cff
5
5
  SHA512:
6
- metadata.gz: 6f6f55143125ef7cf87457a53bb66edb4c3b353fb710e8513cf85e893f969d7cb3b95a78d98429fef5c55b8b25fb4306455ecb1cf9c77c449c71d1ad2dedba84
7
- data.tar.gz: 9539a3d5ad7577a119f30bb69596c8cb279d1d45818574b26f22c1f71613cac0ba785268a56797f57266b5533de8cc159fa42f9055643d8272a141642b024813
6
+ metadata.gz: 90dce4aefb3417a50651f442b5e14d329f339b7c9ddafb9dbddfdac8ef21c52555354024a776420ef619bc75398ba9935f682b90c905bd0db58fab4f19ba5d0a
7
+ data.tar.gz: 432da197590f3454f5eca393b33d9e43b7ce54a27b8a938af0a0397961e328ff6f8c6c62605819d6407c0ed7544df587fa55b0f52040205facea3c255b66cae9
data/lib/jcr/jcr.rb CHANGED
@@ -24,6 +24,7 @@ require 'jcr/find_roots'
24
24
  require 'jcr/map_rule_names'
25
25
  require 'jcr/process_directives'
26
26
  require 'jcr/version'
27
+ require 'jcr/parts'
27
28
 
28
29
  module JCR
29
30
 
@@ -198,6 +199,10 @@ module JCR
198
199
  options[:testjcr] = true
199
200
  end
200
201
 
202
+ opt.on("--process-parts", "creates smaller files for specification writing" ) do |parts|
203
+ options[:process_parts] = true
204
+ end
205
+
201
206
  opt.on("-S STRING","name of root rule. All roots will be tried if none is specified") do |root_name|
202
207
  if options[:root_name]
203
208
  puts "A root has already been specified. Use -h for help.", ""
@@ -283,6 +288,11 @@ module JCR
283
288
  end
284
289
  end
285
290
 
291
+ if options[:process_parts]
292
+ parts = JCR::JcrParts.new
293
+ parts.process_ruleset( options[:ruleset] )
294
+ end
295
+
286
296
  if options[:testjcr]
287
297
  #we got this far which means the JCR was already parsed without
288
298
  #issue. therefore return 0
data/lib/jcr/parts.rb ADDED
@@ -0,0 +1,107 @@
1
+ # Copyright (c) 2017 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ module JCR
16
+
17
+ # This class extracts parts of a JCR file into multiple files based
18
+ # on comments in the file. It can also create a new file without the
19
+ # comments. This is useful for JCR going into specification documents
20
+ # where it is nice to break the JCR up for illustrative purposes in
21
+ # the specification but to also have one JCR file for programmatic
22
+ # testing purposes.
23
+ #
24
+ # The file parts are extracted using the comments
25
+ # ; start_part FILENAME
26
+ # and
27
+ # ; end_part
28
+ # The comments must also be the only thing present on the line
29
+ # though leading whitespace is allowed if desired.
30
+ #
31
+ # To get a new file with all parts be these comments, use this
32
+ # ; all_parts FILENAME
33
+
34
+ class JcrParts
35
+
36
+ # Determines if the the line is a start_part comment.
37
+ # Return the file name otherwise nil
38
+ def get_start( line )
39
+ retval = nil
40
+ m = /^\s*;\s*start_part\s*(.+)[^\s]*/.match( line )
41
+ if m && m[1]
42
+ retval = m[1]
43
+ end
44
+ return retval
45
+ end
46
+
47
+ # Determines if the the line is an all_parts comment.
48
+ # Return the file name otherwise nil
49
+ def get_all( line )
50
+ retval = nil
51
+ m = /^\s*;\s*all_parts\s*(.+)[^\s]*/.match( line )
52
+ if m && m[1]
53
+ retval = m[1]
54
+ end
55
+ return retval
56
+ end
57
+
58
+ # Determines if the the line is an end_parts comment.
59
+ # Return true otherwise nil
60
+ def get_end( line )
61
+ retval = nil
62
+ m = /^\s*;\s*end_part/.match( line )
63
+ if m
64
+ retval = true
65
+ end
66
+ return retval
67
+ end
68
+
69
+ # processes the lines
70
+ # ruleset is to be a string read in using File.read
71
+ def process_ruleset( ruleset )
72
+ all_parts = []
73
+ all_parts_name = nil
74
+ current_part = nil
75
+ current_part_name = nil
76
+ ruleset.lines do |line|
77
+ if !all_parts_name && ( all_parts_name = get_all( line ) )
78
+ # do_nothing
79
+ elsif ( current_part_name = get_start( line ) )
80
+ if current_part
81
+ current_part.close
82
+ end
83
+ current_part = File.open( current_part_name, "w" )
84
+ elsif get_end( line ) && current_part
85
+ current_part.close
86
+ current_part = nil
87
+ elsif current_part
88
+ current_part.puts line
89
+ all_parts << line
90
+ else
91
+ all_parts << line
92
+ end
93
+ end
94
+ if current_part
95
+ current_part.close
96
+ end
97
+ if all_parts_name
98
+ f = File.open( all_parts_name, "w" )
99
+ all_parts.each do |line|
100
+ f.puts( line )
101
+ end
102
+ f.close
103
+ end
104
+ end
105
+
106
+ end
107
+ end
data/lib/jcr/version.rb CHANGED
@@ -15,6 +15,6 @@
15
15
 
16
16
  module JCR
17
17
 
18
- VERSION = "0.7.0"
18
+ VERSION = "0.8.0"
19
19
 
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jcrvalidator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-03 00:00:00.000000000 Z
12
+ date: 2017-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -68,7 +68,6 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: 0.1.4
70
70
  description: A JSON Content Rules (JCR) Validator library and command line utility.
71
- Version 0.6.x is closely following -07 of the draft.
72
71
  email: andy@arin.net
73
72
  executables:
74
73
  - jcr
@@ -88,6 +87,7 @@ files:
88
87
  - lib/jcr/jcr.rb
89
88
  - lib/jcr/map_rule_names.rb
90
89
  - lib/jcr/parser.rb
90
+ - lib/jcr/parts.rb
91
91
  - lib/jcr/process_directives.rb
92
92
  - lib/jcr/version.rb
93
93
  homepage: https://github.com/arineng/jcrvalidator