tidy_json 0.4.0 → 0.5.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: bf122c3cc2a34f2252b766f1a47f52bada4c4ff5b5334555ea62a572848d8531
4
- data.tar.gz: bcd9134752408044711fc2b4ff3732afba7b65995b9c511c9df7e8fe666df4b5
3
+ metadata.gz: 53537db0fe360e1e7d7fe1ba75cb91418c6efa9ee9f108c2f8a2e3020bffed39
4
+ data.tar.gz: f665d2faff39441554d62de9cf91a6af9462d146501f1ba979d0b5ea21785e9d
5
5
  SHA512:
6
- metadata.gz: 0d9d164a90b41f3c5793ebaa04b361a5e1c15bf8ed7580a367421e08c06bcc7cd0f5f8555adc1e9adcff57585c59554472b129797343f78714f964c45c8a7ce6
7
- data.tar.gz: 950f0eab8248273ce6b80a37918226d2637f436b99552844450bec62d6b3ab40dbe887c81c6fadc4baabd53dc1a2faaac834e6e68082b17d6fd1ac0d709d16ba
6
+ metadata.gz: 01d9f6899b775b39c1cad8acbdf9bdbf563f5a61bd74ca5e395c47d0acb0cc8f963328d5a617c2366aeccd70d5b2f2d423c59485e828055e8743b945e45afd52
7
+ data.tar.gz: ae1c4ce4ee8b0b123b3627c694bfb9a2acec49b53387d830ce6acd2215347305552e6fbe2248197991f47ab0be07cd2888c824bb71fee3f56a86678dd05a063c
data/Gemfile CHANGED
@@ -7,3 +7,10 @@ gemspec
7
7
  group :test do
8
8
  gem 'rake'
9
9
  end
10
+
11
+ group :development do
12
+ install_if -> { ENV['COVERAGE'] } do
13
+ gem 'simplecov'
14
+ gem 'simplecov-cobertura'
15
+ end
16
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # tidy_json
2
2
 
3
- ![Gem Version][gem_version_badge] ![Downloads][gem_downloads] [![Travis CI][travis_build_status_badge]][travis_build_status] [![Circle CI][cci_build_status_badge]][cci_build_status] [![codecov][codecov_badge]][codecov_status]
3
+ ![Gem Version][gem_version_badge] ![Downloads][gem_downloads] [![Travis CI][travis_build_status_badge]][travis_build_status] [![codecov][codecov_badge]][codecov_status]
4
4
 
5
5
  A mixin providing (recursive) JSON serialization and pretty printing.
6
6
 
@@ -107,7 +107,8 @@ After [installing the gem][], pass the name of a file containing JSON to `jtidy`
107
107
  formatting options:
108
108
 
109
109
  ```
110
- jtidy FILE[.json] [-i [2,4,6,8,10,12]] [-p [1..8]] [-v [1..8]] [-o D] [-a D] [-m N] [-e] [-A] [-N] [-s] [-P]
110
+ jtidy FILE[.json] [-d out[.json]] [-i [2,4,6,8,10,12]] [-p [1..8]] [-v [1..8]] [-o D] [-a D] [-m N] [-e] [-A] [-N] [-s] [-f] [-P]
111
+ -d, --dest out[.json] Name of output file
111
112
  -i, --indent [2,4,6,8,10,12] The number of spaces to indent each object member [2]
112
113
  -p, --prop-name-space [1..8] The number of spaces to put after property names [0]
113
114
  -v, --value-space [1..8] The number of spaces to put before property values [1]
@@ -118,6 +119,7 @@ jtidy FILE[.json] [-i [2,4,6,8,10,12]] [-p [1..8]] [-v [1..8]] [-o D] [-a D] [-m
118
119
  -A, --ascii Generate ASCII characters only [false]
119
120
  -N, --nan Allow NaN, Infinity and -Infinity [false]
120
121
  -s, --sort Sort property names [false]
122
+ -f, --force Overwrite source file [false]
121
123
  -P, --preview Show preview of output [false]
122
124
  -V, --version Show version
123
125
  -h, --help Show this help message
@@ -134,12 +136,10 @@ More information is available [here](https://github.com/jtidy/jtidy/blob/master/
134
136
  Distributed under the terms of the [MIT License][].
135
137
 
136
138
 
137
- [travis_build_status]: https://travis-ci.com/rdipardo/tidy_json
138
- [cci_build_status]: https://circleci.com/gh/rdipardo/tidy_json/tree/testing
139
- [cci_build_status_badge]: https://circleci.com/gh/rdipardo/tidy_json.svg?style=svg
140
- [travis_build_status_badge]: https://travis-ci.com/rdipardo/tidy_json.svg?branch=master
141
- [codecov_status]: https://codecov.io/gh/rdipardo/tidy_json/branch/testing
142
- [codecov_badge]: https://codecov.io/gh/rdipardo/tidy_json/branch/testing/graph/badge.svg
139
+ [travis_build_status]: https://app.travis-ci.com/github/rdipardo/tidy_json
140
+ [travis_build_status_badge]: https://app.travis-ci.com/rdipardo/tidy_json.svg?branch=master
141
+ [codecov_status]: https://codecov.io/gh/rdipardo/tidy_json/branch/master
142
+ [codecov_badge]: https://codecov.io/gh/rdipardo/tidy_json/branch/master/graph/badge.svg
143
143
  [gem_version_badge]: https://img.shields.io/gem/v/tidy_json?color=%234ec820&label=gem%20version&logo=ruby&logoColor=%23e9573f
144
144
  [gem_downloads]: https://img.shields.io/gem/dt/tidy_json?logo=ruby&logoColor=%23e9573f
145
145
  [MIT License]: https://github.com/rdipardo/tidy_json/blob/master/LICENSE
data/bin/jtidy CHANGED
@@ -7,6 +7,7 @@ require_relative 'jtidy_info'
7
7
 
8
8
  class Jtidy # :nodoc:
9
9
  OPTIONS = {
10
+ '-d out[.json]': [:dest, String, '--dest', 'Name of output file'],
10
11
  '-i [2,4,6,8,10,12]': [:indent, Integer, '--indent [2,4,6,8,10,12]',
11
12
  'The number of spaces to indent each object member [2]'],
12
13
  '-p [1..8]': [:space_before, Integer, '--prop-name-space [1..8]',
@@ -24,6 +25,7 @@ class Jtidy # :nodoc:
24
25
  '-A': [:ascii_only, nil, '--ascii', 'Generate ASCII characters only [false]'],
25
26
  '-N': [:allow_nan, nil, '--nan', 'Allow NaN, Infinity and -Infinity [false]'],
26
27
  '-s': [:sort, nil, '--sort', 'Sort property names [false]'],
28
+ '-f': [:force, nil, '--force', 'Overwrite source file [false]'],
27
29
  # script-only options
28
30
  '-P': [:preview, nil, '--preview', 'Show preview of output [false]']
29
31
  }.freeze
@@ -93,16 +95,23 @@ begin
93
95
  raise OptionParser::InvalidArgument
94
96
  end
95
97
 
96
- if !INPUT_FILE.nil? && !INPUT_FILE.empty?
98
+ if !(INPUT_FILE.nil? || INPUT_FILE.strip.empty?)
97
99
  tidy = ''
98
- fname = INPUT_FILE.gsub('\\', '/')
100
+ fname = INPUT_FILE.strip.gsub('\\', '/')
99
101
  ext = File.extname(fname)
100
102
  input = File.join(
101
103
  File.expand_path(File.dirname(fname)), File.basename(fname, ext)
102
- )
104
+ ).to_s
105
+ outfile = unless OPTS[:dest].nil? || OPTS[:dest].strip.empty?
106
+ fname = OPTS[:dest].strip.gsub('\\', '/')
107
+ ext = File.extname(fname)
108
+ File.join(
109
+ File.expand_path(File.dirname(fname)), File.basename(fname, ext)
110
+ ).to_s
111
+ end
103
112
 
104
113
  begin
105
- File.open((input + '.json').to_s, 'r') do |json|
114
+ File.open((input + '.json'), 'r') do |json|
106
115
  begin
107
116
  tidy = TidyJson.tidy(JSON.parse(json.read.strip), OPTS)
108
117
  rescue JSON::JSONError => e
@@ -111,7 +120,13 @@ begin
111
120
  end
112
121
 
113
122
  if tidy.length.positive?
114
- output = (input + '-tidy.json').to_s
123
+ output = (if OPTS[:force]
124
+ outfile.nil? ? input : outfile
125
+ elsif Regexp.new("(#{outfile})", Regexp::IGNORECASE) =~ input
126
+ warn "Can't overwrite #{input}.json without '--force' option"
127
+ "#{input}-tidy"
128
+ else outfile
129
+ end) + '.json'
115
130
  File.open(output, 'w') { |fd| fd.write(tidy) }
116
131
  puts "\nWrote: #{output}"
117
132
  puts "#{tidy[0..1024]}\n . . ." if OPTS[:preview]
data/bin/jtidy_info.rb CHANGED
@@ -20,9 +20,9 @@ module TidyJson # :nodoc:
20
20
  def initialize
21
21
  gem = Gem::Specification.find_by_name('tidy_json')
22
22
  @meta = {
23
- name: "jtidy #{gem.version}",
24
- license: "License: #{gem.license}",
25
- bugs: "Bugs: #{gem.metadata['bug_tracker_uri']}",
23
+ name: "# jtidy #{gem.version}",
24
+ license: "# License: #{gem.license}",
25
+ bugs: "# Bugs: #{gem.metadata['bug_tracker_uri']}",
26
26
  notice: NOTICE
27
27
  }
28
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TidyJson
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -7,8 +7,8 @@ if ENV['COVERAGE']
7
7
  SimpleCov.command_name 'Unit Tests'
8
8
 
9
9
  if ENV['CI']
10
- require 'codecov'
11
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
10
+ require 'simplecov-cobertura'
11
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
12
12
  end
13
13
  rescue LoadError
14
14
  warn "Can't locate coverage drivers! Try running: `bundle install` first."
data/tidy_json.gemspec CHANGED
@@ -25,8 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = ['jtidy']
26
26
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3')
27
27
  spec.add_runtime_dependency 'json', '~> 2.5'
28
- spec.add_development_dependency 'codecov', '~> 0.2.5'
29
- spec.add_development_dependency 'simplecov', '~> 0.17'
30
28
  spec.add_development_dependency 'test-unit', '~> 3.4'
31
29
  spec.add_development_dependency 'yard', '~> 0.9'
32
30
  spec.rdoc_options = ['-x test/*']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidy_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Di Pardo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-20 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.5'
27
- - !ruby/object:Gem::Dependency
28
- name: codecov
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.2.5
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.2.5
41
- - !ruby/object:Gem::Dependency
42
- name: simplecov
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.17'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.17'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: test-unit
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -143,11 +115,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
115
  - !ruby/object:Gem::Version
144
116
  version: '0'
145
117
  requirements: []
146
- rubygems_version: 3.2.3
147
- signing_key:
118
+ rubygems_version: 3.2.22
119
+ signing_key:
148
120
  specification_version: 4
149
121
  summary: Serialize any Ruby object as readable JSON
150
122
  test_files:
151
123
  - test/JsonableObject.json
152
124
  - test/codecov_runner.rb
153
125
  - test/test_tidy_json.rb
126
+ ...