check_please 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8c12644a3f83d1d263374a88b825a9f705f55d68582e90a50a3065ec2b0105e
4
- data.tar.gz: 3f5ddc8b0d9e5c02bc4845e5a4ac21d07b358f75639146f32c71143bc1e6d605
3
+ metadata.gz: 2bd44bf6bcc771bf5d0179fa562f5ddff80f0ed4bb2420ede197d60007d8057d
4
+ data.tar.gz: 7c0725d4b8cf3d03d7c8ffd2e8df51a8e5a1616e86c4cad02695dca73921340f
5
5
  SHA512:
6
- metadata.gz: c95071934105bc8c8876287bf460a0466ecc996eab6356c64a994566824c95d2f24d6d446bc8bcc6d4d66b0a224023a4347839e75f5d8204860e9e2210e7e07d
7
- data.tar.gz: ebdbe6bdeafd3f71bf9461f5eccd73f20772043d9e84ab01fa91c0a1dcff054a21c74d718aa40cf0c89bed3219d36d1f46e89ce37ea6d27483bb268518bb7d59
6
+ metadata.gz: 0add2fc010b651ae30a1309c3df9b26c1280e40fc7c45b5214ad22922fb3103c533f0f0ebbf26d46c3dbfb97b09d36ded3c9a419818039437aed2d198ced4669
7
+ data.tar.gz: 88611e7acca8a803f69e48ddefddfbc208faeae359fc3417b0f0faa0aae11e853a45891919290abd062f503558f0caedc3b05fa037397f3b4142b11a3905245c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- check_please (0.5.3)
4
+ check_please (0.5.4)
5
5
  table_print
6
6
 
7
7
  GEM
data/lib/check_please.rb CHANGED
@@ -7,17 +7,18 @@ require "check_please/error"
7
7
  require "check_please/version"
8
8
 
9
9
  module CheckPlease
10
- autoload :Reification, "check_please/reification"
11
- autoload :CLI, "check_please/cli"
12
- autoload :Comparison, "check_please/comparison"
13
- autoload :Diff, "check_please/diff"
14
- autoload :Diffs, "check_please/diffs"
15
- autoload :Flag, "check_please/flag"
16
- autoload :Flags, "check_please/flags"
17
- autoload :Path, "check_please/path"
18
- autoload :PathSegment, "check_please/path_segment"
19
- autoload :Printers, "check_please/printers"
20
- autoload :Refinements, "check_please/refinements"
10
+ autoload :Reification, "check_please/reification"
11
+ autoload :CLI, "check_please/cli"
12
+ autoload :Comparison, "check_please/comparison"
13
+ autoload :Diff, "check_please/diff"
14
+ autoload :Diffs, "check_please/diffs"
15
+ autoload :Flag, "check_please/flag"
16
+ autoload :Flags, "check_please/flags"
17
+ autoload :Path, "check_please/path"
18
+ autoload :PathSegment, "check_please/path_segment"
19
+ autoload :PathSegmentMatcher, "check_please/path_segment_matcher"
20
+ autoload :Printers, "check_please/printers"
21
+ autoload :Refinements, "check_please/refinements"
21
22
  end
22
23
 
23
24
 
@@ -13,7 +13,7 @@ module CheckPlease
13
13
  catch(:max_diffs_reached) do
14
14
  compare reference, candidate, CheckPlease::Path.root
15
15
  end
16
- diffs
16
+ diffs.filter_by_flags(@flags)
17
17
  end
18
18
 
19
19
  private
@@ -47,6 +47,11 @@ module CheckPlease
47
47
  @list.map(&:attributes)
48
48
  end
49
49
 
50
+ def filter_by_flags(flags)
51
+ new_list = @list.reject { |diff| Path.new(diff.path).excluded?(flags) }
52
+ self.class.new(new_list, flags: flags)
53
+ end
54
+
50
55
  def to_s(flags = {})
51
56
  CheckPlease::Printers.render(self, flags)
52
57
  end
@@ -17,7 +17,12 @@ module CheckPlease
17
17
  def initialize(name_or_segments = [])
18
18
  case name_or_segments
19
19
  when String, Symbol, Numeric, nil
20
- names = name_or_segments.to_s.split(SEPARATOR)
20
+ string = name_or_segments.to_s
21
+ if string =~ %r(//)
22
+ raise InvalidPath, "paths cannot have empty segments"
23
+ end
24
+
25
+ names = string.split(SEPARATOR)
21
26
  names.shift until names.empty? || names.first =~ /\S/
22
27
  segments = PathSegment.reify(names)
23
28
  when Array
@@ -26,10 +31,6 @@ module CheckPlease
26
31
  raise InvalidPath, "not sure what to do with #{name_or_segments.inspect}"
27
32
  end
28
33
 
29
- if segments.any?(&:empty?)
30
- raise InvalidPath, "#{self.class.name} cannot contain empty segments"
31
- end
32
-
33
34
  @segments = Array(segments)
34
35
 
35
36
  @to_s = SEPARATOR + @segments.join(SEPARATOR)
@@ -124,7 +125,7 @@ module CheckPlease
124
125
  # (as of this writing, this should never actually happen, but I'm being thorough)
125
126
  def ancestor_on_list?(paths)
126
127
  paths.any? { |path|
127
- ancestors.any? { |ancestor| ancestor == path }
128
+ ancestors.any? { |ancestor| ancestor.match?(path) }
128
129
  }
129
130
  end
130
131
 
@@ -153,7 +154,7 @@ module CheckPlease
153
154
 
154
155
  # O(n) check to see if the path itself is on a list
155
156
  def self_on_list?(paths)
156
- paths.any? { |path| self == path }
157
+ paths.any? { |path| self.match?(path) }
157
158
  end
158
159
 
159
160
  def too_deep?(flags)
@@ -30,19 +30,16 @@ module CheckPlease
30
30
 
31
31
  def initialize(name = nil)
32
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
33
+
34
+ case @name
35
+ when "", /\s/ # blank or has any whitespace
36
+ raise InvalidPathSegment, "#{name.inspect} is not a valid #{self.class} name"
37
37
  end
38
+
38
39
  parse_key_and_value
39
40
  freeze
40
41
  end
41
42
 
42
- def empty?
43
- name.empty?
44
- end
45
-
46
43
  def key_expr?
47
44
  name.match?(KEY_EXPR)
48
45
  end
@@ -52,23 +49,12 @@ module CheckPlease
52
49
  end
53
50
 
54
51
  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
52
+ other = reify(other_segment_or_string)
53
+ PathSegmentMatcher.call(self, other)
64
54
  end
65
55
 
66
- protected
67
-
68
- def match_type
69
- return :key if key_expr?
70
- return :key_value if key_val_expr?
71
- :plain
56
+ def splat?
57
+ name == '*'
72
58
  end
73
59
 
74
60
  private
@@ -0,0 +1,44 @@
1
+ module CheckPlease
2
+
3
+ class PathSegmentMatcher
4
+ def self.call(a,b)
5
+ new(a,b).call
6
+ end
7
+
8
+ attr_reader :a, :b, :types
9
+ def initialize(a, b)
10
+ @a, @b = a, b
11
+ @types = [ _type(a), _type(b) ].sort
12
+ end
13
+
14
+ def call
15
+ return true if either?(:splat)
16
+ return a.name == b.name if both?(:plain)
17
+ return a.key == b.key if key_and_key_value?
18
+
19
+ false
20
+ end
21
+
22
+ private
23
+
24
+ def _type(x)
25
+ return :splat if x.splat?
26
+ return :key if x.key_expr?
27
+ return :key_value if x.key_val_expr?
28
+ :plain
29
+ end
30
+
31
+ def both?(type)
32
+ types.uniq == [type]
33
+ end
34
+
35
+ def either?(type)
36
+ types.include?(type)
37
+ end
38
+
39
+ def key_and_key_value?
40
+ types == [ :key, :key_value ]
41
+ end
42
+ end
43
+
44
+ end
@@ -1,5 +1,5 @@
1
1
  module CheckPlease
2
2
  # NOTE: 'check_please_rspec_matcher' depends on this,
3
3
  # so try to keep them roughly in sync
4
- VERSION = "0.5.3" # about to release? rerun `bundle lock` to update Gemfile.lock
4
+ VERSION = "0.5.4" # about to release? rerun `bundle lock` to update Gemfile.lock
5
5
  end
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.5.3
4
+ version: 0.5.4
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: 2021-02-04 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print
@@ -87,6 +87,7 @@ files:
87
87
  - lib/check_please/flags.rb
88
88
  - lib/check_please/path.rb
89
89
  - lib/check_please/path_segment.rb
90
+ - lib/check_please/path_segment_matcher.rb
90
91
  - lib/check_please/printers.rb
91
92
  - lib/check_please/printers/base.rb
92
93
  - lib/check_please/printers/json.rb