check_please 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +0 -2
- data/Rakefile +16 -1
- data/lib/check_please.rb +3 -3
- data/lib/check_please/cli.rb +19 -3
- data/lib/check_please/cli/flag.rb +1 -0
- data/lib/check_please/comparison.rb +9 -3
- data/lib/check_please/diffs.rb +8 -1
- data/lib/check_please/path.rb +4 -0
- data/lib/check_please/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33a26fc2e249e7ff6bba107ba2da856f0f70a9e232862b3650893b1844117cac
|
4
|
+
data.tar.gz: c8624e0cfc38a4f7bcd9db9af22215f0d2d6311ab061ec156318894fa8a01b60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c0b1d909dbdaf606a0376f38062eaaa26bd19573413ce0d81002b120aa247176d7a564752b83f6ac9a359974df32a7a5c2997f20468f95d683b28369d5548b
|
7
|
+
data.tar.gz: 78fe71950e42986ef0b9857984310fa51955d08a5b1b9b432d2b277fb9191b188b173f78575d0f88a927d4668065ac35fc32f1d74bba082894f897c0d9896267
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -163,8 +163,6 @@ print diffs as JSON to facilitate parsing. In Ruby, pass `format: :json` to
|
|
163
163
|
## TODO
|
164
164
|
|
165
165
|
* command line flags for :allthethings:!
|
166
|
-
* --fail-fast
|
167
|
-
* limit to first N
|
168
166
|
* sort by path?
|
169
167
|
* max depth (for iterative refinement?)
|
170
168
|
* detect timestamps and compare after parsing?
|
data/Rakefile
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
|
4
|
+
namespace :spec do
|
5
|
+
RSpec::Core::RakeTask.new(:all)
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:not_cli) do |t|
|
8
|
+
t.rspec_opts = "--tag ~cli"
|
9
|
+
end
|
10
|
+
task fast: :not_cli
|
11
|
+
|
12
|
+
# These are much slower than the rest, since they use Kernel#`
|
13
|
+
RSpec::Core::RakeTask.new(:cli) do |t|
|
14
|
+
t.rspec_opts = "--tag cli"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# By default, `rake spec` should run fast specs first, then cli if those all pass
|
19
|
+
task :spec => [ "spec:not_cli", "spec:cli" ]
|
5
20
|
|
6
21
|
task :default => :spec
|
data/lib/check_please.rb
CHANGED
@@ -10,14 +10,14 @@ require_relative "check_please/cli"
|
|
10
10
|
module CheckPlease
|
11
11
|
ELEVATOR_PITCH = "Tool for parsing and diffing two JSON documents."
|
12
12
|
|
13
|
-
def self.diff(reference, candidate)
|
13
|
+
def self.diff(reference, candidate, options = {})
|
14
14
|
reference = maybe_parse(reference)
|
15
15
|
candidate = maybe_parse(candidate)
|
16
|
-
Comparison.perform(reference, candidate)
|
16
|
+
Comparison.perform(reference, candidate, options)
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.render_diff(reference, candidate, options = {})
|
20
|
-
diffs = diff(reference, candidate)
|
20
|
+
diffs = diff(reference, candidate, options)
|
21
21
|
Printers.render(diffs, options)
|
22
22
|
end
|
23
23
|
|
data/lib/check_please/cli.rb
CHANGED
@@ -13,17 +13,33 @@ module CheckPlease
|
|
13
13
|
|
14
14
|
|
15
15
|
FLAGS = []
|
16
|
-
def self.flag(
|
17
|
-
flag = Flag.new(
|
16
|
+
def self.flag(long:, short: nil, &block)
|
17
|
+
flag = Flag.new(short, long, &block)
|
18
18
|
FLAGS << flag
|
19
19
|
end
|
20
20
|
|
21
21
|
##### Define CLI flags here #####
|
22
22
|
|
23
|
-
flag "-f FORMAT", "--format FORMAT" do |f|
|
23
|
+
flag short: "-f FORMAT", long: "--format FORMAT" do |f|
|
24
24
|
f.desc = "format in which to present diffs (available options: [#{CheckPlease::Printers::FORMATS.join(", ")}])"
|
25
25
|
f.set_key :format, :to_sym
|
26
26
|
end
|
27
|
+
|
28
|
+
flag short: "-n MAX_DIFFS", long: "--max-diffs MAX_DIFFS" do |f|
|
29
|
+
f.desc = "Stop after encountering a specified number of diffs"
|
30
|
+
f.set_key :max_diffs, :to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
flag long: "--fail-fast" do |f|
|
34
|
+
f.desc = "Stop after encountering the very first diff"
|
35
|
+
f.set_key(:max_diffs) { 1 }
|
36
|
+
end
|
37
|
+
|
38
|
+
flag short: "-d MAX_DEPTH", long: "--max-depth MAX_DEPTH" do |f|
|
39
|
+
f.desc = "Limit the number of levels to descend when comparing documents (NOTE: root has depth=1)"
|
40
|
+
f.set_key :max_depth, :to_i
|
41
|
+
end
|
42
|
+
|
27
43
|
end
|
28
44
|
|
29
45
|
end
|
@@ -3,16 +3,22 @@ module CheckPlease
|
|
3
3
|
module Comparison
|
4
4
|
extend self
|
5
5
|
|
6
|
-
def perform(reference, candidate)
|
6
|
+
def perform(reference, candidate, options = {})
|
7
7
|
root = CheckPlease::Path.new
|
8
|
-
diffs = Diffs.new
|
9
|
-
|
8
|
+
diffs = Diffs.new(options: options)
|
9
|
+
catch(:max_diffs_reached) do
|
10
|
+
compare reference, candidate, root, diffs
|
11
|
+
end
|
10
12
|
diffs
|
11
13
|
end
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
17
|
def compare(ref, can, path, diffs)
|
18
|
+
if (d = diffs.options[:max_depth])
|
19
|
+
return if path.depth > d
|
20
|
+
end
|
21
|
+
|
16
22
|
case types(ref, can)
|
17
23
|
when [ :array, :array ] ; compare_arrays ref, can, path, diffs
|
18
24
|
when [ :hash, :hash ] ; compare_hashes ref, can, path, diffs
|
data/lib/check_please/diffs.rb
CHANGED
@@ -5,7 +5,9 @@ module CheckPlease
|
|
5
5
|
# Custom collection class for Diff instances.
|
6
6
|
# Can retrieve members using indexes or paths.
|
7
7
|
class Diffs
|
8
|
-
|
8
|
+
attr_reader :options
|
9
|
+
def initialize(diff_list = nil, options: {})
|
10
|
+
@options = options
|
9
11
|
@list = []
|
10
12
|
@hash = {}
|
11
13
|
Array(diff_list).each do |diff|
|
@@ -27,6 +29,11 @@ module CheckPlease
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def <<(diff)
|
32
|
+
if (n = options[:max_diffs])
|
33
|
+
# It seems no one can help me now / I'm in too deep, there's no way out
|
34
|
+
throw :max_diffs_reached if length >= n
|
35
|
+
end
|
36
|
+
|
30
37
|
@list << diff
|
31
38
|
@hash[diff.path] = diff
|
32
39
|
end
|
data/lib/check_please/path.rb
CHANGED
data/lib/check_please/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_please
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Livingston-Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: table_print
|