check_please 0.4.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile.lock +1 -1
- data/README.md +301 -29
- data/Rakefile +50 -3
- data/bin/gh-md-toc +350 -0
- data/lib/check_please.rb +77 -25
- data/lib/check_please/cli.rb +1 -1
- data/lib/check_please/cli/parser.rb +1 -1
- data/lib/check_please/comparison.rb +176 -40
- data/lib/check_please/diffs.rb +4 -5
- data/lib/check_please/error.rb +24 -0
- data/lib/check_please/flag.rb +13 -3
- data/lib/check_please/path.rb +148 -13
- data/lib/check_please/path_segment.rb +88 -0
- data/lib/check_please/reification.rb +50 -0
- data/lib/check_please/version.rb +1 -1
- data/usage_examples.rb +24 -2
- metadata +5 -2
@@ -0,0 +1,88 @@
|
|
1
|
+
module CheckPlease
|
2
|
+
|
3
|
+
class PathSegment
|
4
|
+
include CheckPlease::Reification
|
5
|
+
can_reify String, Symbol, Numeric, nil
|
6
|
+
|
7
|
+
KEY_EXPR = %r{
|
8
|
+
^
|
9
|
+
\: # a literal colon
|
10
|
+
( # capture key
|
11
|
+
[^\:]+ # followed by one or more things that aren't colons
|
12
|
+
) # end capture key
|
13
|
+
$
|
14
|
+
}x
|
15
|
+
|
16
|
+
KEY_VAL_EXPR = %r{
|
17
|
+
^
|
18
|
+
( # capture key
|
19
|
+
[^=]+ # stuff (just not an equal sign)
|
20
|
+
) # end capture key
|
21
|
+
\= # an equal sign
|
22
|
+
( # capture key value
|
23
|
+
[^=]+ # stuff (just not an equal sign)
|
24
|
+
) # end capture key value
|
25
|
+
$
|
26
|
+
}x
|
27
|
+
|
28
|
+
attr_reader :name, :key, :key_value
|
29
|
+
alias_method :to_s, :name
|
30
|
+
|
31
|
+
def initialize(name = nil)
|
32
|
+
@name = name.to_s.strip
|
33
|
+
if @name =~ %r(\s) # has any whitespace
|
34
|
+
raise InvalidPathSegment, <<~EOF
|
35
|
+
#{name.inspect} is not a valid #{self.class} name
|
36
|
+
EOF
|
37
|
+
end
|
38
|
+
parse_key_and_value
|
39
|
+
freeze
|
40
|
+
end
|
41
|
+
|
42
|
+
def empty?
|
43
|
+
name.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def key_expr?
|
47
|
+
name.match?(KEY_EXPR)
|
48
|
+
end
|
49
|
+
|
50
|
+
def key_val_expr?
|
51
|
+
name.match?(KEY_VAL_EXPR)
|
52
|
+
end
|
53
|
+
|
54
|
+
def match?(other_segment_or_string)
|
55
|
+
other = self.class.reify(other_segment_or_string)
|
56
|
+
|
57
|
+
match_types = [ self.match_type, other.match_type ]
|
58
|
+
case match_types
|
59
|
+
when [ :plain, :plain ] ; self.name == other.name
|
60
|
+
when [ :key, :key_value ] ; self.key == other.key
|
61
|
+
when [ :key_value, :key ] ; self.key == other.key
|
62
|
+
else ; false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def match_type
|
69
|
+
return :key if key_expr?
|
70
|
+
return :key_value if key_val_expr?
|
71
|
+
:plain
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def parse_key_and_value
|
77
|
+
case name
|
78
|
+
when KEY_EXPR
|
79
|
+
@key = $1
|
80
|
+
when KEY_VAL_EXPR
|
81
|
+
@key, @key_value = $1, $2
|
82
|
+
else
|
83
|
+
# :nothingtodohere:
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CheckPlease
|
2
|
+
|
3
|
+
module Reification
|
4
|
+
def self.included(receiver)
|
5
|
+
receiver.extend ClassMethods
|
6
|
+
receiver.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def reifiable
|
11
|
+
@_reifiable ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_reify(*klasses)
|
15
|
+
klasses.flatten!
|
16
|
+
|
17
|
+
unless ( klasses - [nil] ).all? { |e| e.is_a?(Class) }
|
18
|
+
raise ArgumentError, "classes (or nil) only, please"
|
19
|
+
end
|
20
|
+
|
21
|
+
reifiable.concat klasses
|
22
|
+
reifiable.uniq!
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def reify(primitive_or_object)
|
27
|
+
case primitive_or_object
|
28
|
+
when self ; return primitive_or_object
|
29
|
+
when Array ; return primitive_or_object.map { |e| reify(e) }
|
30
|
+
when *reifiable ; return new(primitive_or_object)
|
31
|
+
end
|
32
|
+
# note early return ^^^
|
33
|
+
|
34
|
+
# that didn't work? complain!
|
35
|
+
acceptable = reifiable.map { |e| Class === e ? e.name : e.inspect }
|
36
|
+
raise ArgumentError, <<~EOF
|
37
|
+
#{self}.reify was given: #{primitive_or_object.inspect}
|
38
|
+
but only accepts: #{acceptable.join(", ")}
|
39
|
+
EOF
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module InstanceMethods
|
44
|
+
def reify(x)
|
45
|
+
self.class.reify(x)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/check_please/version.rb
CHANGED
data/usage_examples.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'check_please'
|
2
2
|
|
3
|
-
reference = { foo
|
4
|
-
candidate = { bar
|
3
|
+
reference = { "foo" => "wibble" }
|
4
|
+
candidate = { "bar" => "wibble" }
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
##### Printing diffs #####
|
5
9
|
|
6
10
|
puts CheckPlease.render_diff(reference, candidate)
|
7
11
|
|
@@ -12,3 +16,21 @@ _ = <<EOF
|
|
12
16
|
missing | /foo | wibble |
|
13
17
|
extra | /bar | | wibble
|
14
18
|
EOF
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
##### Doing your own thing with diffs #####
|
23
|
+
|
24
|
+
diffs = CheckPlease.diff(reference, candidate)
|
25
|
+
|
26
|
+
# `diffs` is a custom collection (type: CheckPlease::Diffs) that contains
|
27
|
+
# individual Diff objects for you to inspect as you see fit.
|
28
|
+
#
|
29
|
+
# If you come up with a useful way to present these, feel free to submit a PR
|
30
|
+
# with a new class in `lib/check_please/printers` !
|
31
|
+
|
32
|
+
# To print these in the console, you can just do:
|
33
|
+
puts diffs
|
34
|
+
|
35
|
+
# If for some reason you want to print the JSON version, it gets a little more verbose:
|
36
|
+
puts diffs.to_s(format: :json)
|
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.
|
4
|
+
version: 0.5.3
|
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:
|
11
|
+
date: 2021-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: table_print
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- README.md
|
72
72
|
- Rakefile
|
73
73
|
- bin/console
|
74
|
+
- bin/gh-md-toc
|
74
75
|
- bin/setup
|
75
76
|
- check_please.gemspec
|
76
77
|
- exe/check_please
|
@@ -85,11 +86,13 @@ files:
|
|
85
86
|
- lib/check_please/flag.rb
|
86
87
|
- lib/check_please/flags.rb
|
87
88
|
- lib/check_please/path.rb
|
89
|
+
- lib/check_please/path_segment.rb
|
88
90
|
- lib/check_please/printers.rb
|
89
91
|
- lib/check_please/printers/base.rb
|
90
92
|
- lib/check_please/printers/json.rb
|
91
93
|
- lib/check_please/printers/table_print.rb
|
92
94
|
- lib/check_please/refinements.rb
|
95
|
+
- lib/check_please/reification.rb
|
93
96
|
- lib/check_please/version.rb
|
94
97
|
- usage_examples.rb
|
95
98
|
homepage: https://github.com/RealGeeks/check_please
|