check_please 0.3.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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.3.0"
4
+ VERSION = "0.5.2" # about to release? rerun `bundle check` to update Gemfile.lock also
5
5
  end
@@ -1,7 +1,11 @@
1
1
  require 'check_please'
2
2
 
3
- reference = { foo: "wibble" }
4
- candidate = { bar: "wibble" }
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.3.0
4
+ version: 0.5.2
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-19 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print
@@ -71,23 +71,28 @@ 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
77
78
  - lib/check_please.rb
78
79
  - lib/check_please/cli.rb
79
- - lib/check_please/cli/flag.rb
80
80
  - lib/check_please/cli/parser.rb
81
81
  - lib/check_please/cli/runner.rb
82
82
  - lib/check_please/comparison.rb
83
83
  - lib/check_please/diff.rb
84
84
  - lib/check_please/diffs.rb
85
85
  - lib/check_please/error.rb
86
+ - lib/check_please/flag.rb
87
+ - lib/check_please/flags.rb
86
88
  - lib/check_please/path.rb
89
+ - lib/check_please/path_segment.rb
87
90
  - lib/check_please/printers.rb
88
91
  - lib/check_please/printers/base.rb
89
92
  - lib/check_please/printers/json.rb
90
93
  - lib/check_please/printers/table_print.rb
94
+ - lib/check_please/refinements.rb
95
+ - lib/check_please/reification.rb
91
96
  - lib/check_please/version.rb
92
97
  - usage_examples.rb
93
98
  homepage: https://github.com/RealGeeks/check_please
@@ -1,40 +0,0 @@
1
- module CheckPlease
2
- module CLI
3
-
4
- class Flag
5
- ATTR_NAMES = %i[ short long desc key block ]
6
- attr_accessor(*ATTR_NAMES)
7
-
8
- def initialize(*args)
9
- self.short = args.shift if args.any?
10
- self.long = args.shift if args.any?
11
-
12
- yield self if block_given?
13
-
14
- missing = ATTR_NAMES.select { |e| self.send(e).nil? }
15
- missing -= %i[ short ] # short is optional!
16
- if missing.any?
17
- raise ArgumentError, "Missing attributes: #{missing.join(', ')}"
18
- end
19
- end
20
-
21
- def visit_option_parser(parser, options)
22
- parser.on(short, long, desc) do |value|
23
- block.call options, value
24
- end
25
- end
26
-
27
- def set_key(key, message = nil, &b)
28
- raise ArgumentError if message && b
29
- raise ArgumentError if !message && !b
30
-
31
- self.key = key
32
- self.block = ->(options, value) {
33
- b ||= message.to_sym.to_proc
34
- options[key] = b.call(value)
35
- }
36
- end
37
- end
38
-
39
- end
40
- end