object_inspector 0.6.1 → 0.6.3

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: 4b35f6663bb2960940d4c0139ff728c37082c86ffef6a2bfedeb179fcbb54339
4
- data.tar.gz: 53e84daa5e170088aeeaac38845eab86f717dacbebf0d9e795e557cd2e5f0f75
3
+ metadata.gz: d20f26835756f0ebb2f4ecb6371662cc35a4cb9d62e72682a5b76d8e96ca8290
4
+ data.tar.gz: c41e95352adedc432259b57f8ed0be5e16a9a0b7860ba23e5bbd8f8fa1cecf9f
5
5
  SHA512:
6
- metadata.gz: fe9fb99c6ed1b74f269070f697119596f0ec9cfe074453fbc77166349b813163158dbe6ccf58646b340f7a0fca8fdab391da1db17e75986e904eebfca96598d5
7
- data.tar.gz: 65ed4a72973c2cd5b38b56af6cd131d35a6c2c3affc292be8e13e11eae6c222ad10585b4eee3a475d1888fcd4e98cc17c1c1d940ae535f25472b65e815f83759
6
+ metadata.gz: 141e7e013e692ff025d7f6c2bc11f395ed6ff8499c30e5d161d7e5fc0219f2981b688ea1db6c01a80e87363553bf07a5b8319d04db744f688a3839bcf9ff1982
7
+ data.tar.gz: 4a811cba205e011f8d8ce390c89da2aa93dd01e21692ce28516739b35c7907c7f7e416f606c39fdfb92edba237f76ac439175dd90c1fefc498b7e8ad25bbcfae
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Paul Dobbins
3
+ Copyright (c) 2023 Paul DobbinSchmaltz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
- # ObjectInspector
1
+ # Object Inspector
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/object_inspector.svg)](https://badge.fury.io/rb/object_inspector)
4
- [![Build Status](https://travis-ci.org/pdobb/object_inspector.svg?branch=master)](https://travis-ci.org/pdobb/object_inspector)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/test_coverage)](https://codeclimate.com/github/pdobb/object_inspector/test_coverage)
6
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/maintainability)](https://codeclimate.com/github/pdobb/object_inspector/maintainability)
7
5
 
8
- ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, issues, info, and/or a name along with an optional, self-definable scope option to represents objects. Great for the console, logging, etc.
6
+ Object Inspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, issues, info, and/or a name along with an optional, self-definable scope option to represent objects. Great for the console, logging, etc.
9
7
 
10
- Because object inspection code should be uniform, easy to build, and its output should be easy to read!
8
+ Why? Because object inspection code should be uniform, easy to build, and its output should be easy to read!
11
9
 
12
10
  If you'd like to just jump into an example: [Full Example](#full-example).
13
11
 
@@ -32,18 +30,17 @@ Or install it yourself:
32
30
  ## Compatibility
33
31
 
34
32
  Tested MRI Ruby Versions:
35
- * 2.3
36
- * 2.4
37
- * 2.5
38
- * 2.6
39
- * edge
33
+ * 2.7
34
+ * 3.0
35
+ * 3.1
36
+ * 3.2
40
37
 
41
- ObjectInspector has no other dependencies.
38
+ Object Inspector has no other dependencies.
42
39
 
43
40
 
44
41
  ## Configuration
45
42
 
46
- Global/default values for ObjectInspector can be configured via the ObjectInspector::Configuration object.
43
+ Global/default values for Object Inspector can be configured via the ObjectInspector::Configuration object.
47
44
 
48
45
  _Note: In a Rails app, the following would go in e.g. `config/initializers/object_inspector.rb`_
49
46
 
@@ -392,13 +389,13 @@ class MyDelegatingWrapperObject
392
389
  @my_object = my_object
393
390
  end
394
391
 
395
- def inspect(**kargs)
392
+ def inspect(**kwargs)
396
393
  super(identification: self.class.name,
397
394
  name: nil,
398
395
  flags: nil,
399
396
  info: nil,
400
397
  issues: nil,
401
- **kargs)
398
+ **kwargs)
402
399
  end
403
400
 
404
401
  def to_model
@@ -512,7 +509,7 @@ See examples:
512
509
 
513
510
  ## Supporting Gems
514
511
 
515
- ObjectInspector works great with the [ObjectIdentifier](https://github.com/pdobb/object_identifier) gem.
512
+ Object Inspector works great with the [Object Identifier](https://github.com/pdobb/object_identifier) gem.
516
513
 
517
514
  ```ruby
518
515
  class MyObject
@@ -545,14 +542,14 @@ MyObject.new.inspect
545
542
 
546
543
  ## Performance
547
544
 
548
- ### Benchmarking ObjectInspector
545
+ ### Benchmarking Object Inspector
549
546
 
550
547
  ObjectInspetor is ~4x slower than Ruby's default inspect.
551
548
 
552
- Performance of ObjectInspect can be tested by playing the [ObjectInspector Benchmarking Scripts] in the pry console for this gem.
549
+ Performance of Object Inspector can be tested by playing the [Object Inspector Benchmarking Script](https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/object_inspector.rb) in the pry console for this gem.
553
550
 
554
551
  ```ruby
555
- play scripts/benchmarking/object_inspector.rb
552
+ play script/benchmarking/object_inspector.rb
556
553
  # Comparison:
557
554
  # Ruby: 30382.2 i/s
558
555
  # ObjectInspector::Inspector: 7712.2 i/s - 3.94x slower
@@ -563,10 +560,10 @@ play scripts/benchmarking/object_inspector.rb
563
560
 
564
561
  [ObjectInspector::TemplatingFormatter] -- which is the default Formatter -- outperforms [ObjectInspector::CombiningFormatter] by about 30% on average.
565
562
 
566
- Performance of Formatters can be tested by playing the [Formatters Benchmarking Scripts] in the pry console for this gem.
563
+ Performance of Formatters can be tested by playing the [Formatters Benchmarking Scripts](https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/formatters.rb) in the pry console for this gem.
567
564
 
568
565
  ```ruby
569
- play scripts/benchmarking/formatters.rb
566
+ play script/benchmarking/formatters.rb
570
567
  # == Averaged =============================================================
571
568
  # ...
572
569
  #
@@ -585,7 +582,7 @@ Custom Formatters may be similarly gauged for comparison by adding them to the `
585
582
  ```ruby
586
583
  custom_formatter_klasses = [MyCustomFormatter]
587
584
 
588
- play scripts/benchmarking/formatters.rb
585
+ play script/benchmarking/formatters.rb
589
586
  # == Averaged =============================================================
590
587
  # ...
591
588
  #
@@ -600,10 +597,20 @@ play scripts/benchmarking/formatters.rb
600
597
 
601
598
  ## Development
602
599
 
603
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
600
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. Or, run `rake` to run the tests plus linters as well as `yard` (to confirm proper YARD documentation practices). You can also run `bin/console` for an interactive prompt that will allow you to experiment.
604
601
 
605
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
602
+ To install this gem onto your local machine, run `bundle exec rake install`.
606
603
 
604
+ To release a new version, update the version number in `version.rb`, bump the latest ruby target versions etc. with `rake bump`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
605
+
606
+ ### Documentation
607
+
608
+ [YARD documentation](https://yardoc.org/index.html) can be generated and viewed live:
609
+ 1. Install YARD: `gem install yard`
610
+ 2. Run the YARD server: `yard server --reload`
611
+ 3. Open the live documentation site: `open http://localhost:8808`
612
+
613
+ While the YARD server is running, documentation in the live site will be auto-updated on source code save (and site reload).
607
614
 
608
615
  ## Contributing
609
616
 
@@ -617,5 +624,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
617
624
 
618
625
  [ObjectInspector::TemplatingFormatter]: https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/templating_formatter.rb
619
626
  [ObjectInspector::CombiningFormatter]: https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/combining_formatter.rb
620
- [ObjectInspector Benchmarking Scripts]: https://github.com/pdobb/object_inspector/blob/master/scripts/benchmarking/object_inspector.rb
621
- [Formatters Benchmarking Scripts]: https://github.com/pdobb/object_inspector/blob/master/scripts/benchmarking/formatters.rb
627
+ [Object Inspector Benchmarking Scripts]: https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/object_inspector.rb
628
+ [Formatters Benchmarking Scripts]: https://github.com/pdobb/object_inspector/blob/master/script/benchmarking/formatters.rb
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectInspector
4
- # ObjectInspector::Conversions defines conversion functions used by
5
- # ObjectInspector.
6
- module Conversions
7
- module_function
3
+ # ObjectInspector::Conversions defines conversion functions used by
4
+ # ObjectInspector.
5
+ module ObjectInspector::Conversions
6
+ module_function
8
7
 
9
- # Convert the passed in value to an {ObjectInspector::Scope} object.
10
- # Just returns the pass in value if it already is an
11
- # {ObjectInspector::Scope} object.
12
- #
13
- # @return [ObjectInspector::Scope]
14
- def Scope(value) # rubocop:disable Naming/MethodName
15
- case value
16
- when ObjectInspector::Scope
17
- value
18
- else
19
- ObjectInspector::Scope.new(value)
20
- end
8
+ # Convert the passed in value to an {ObjectInspector::Scope} object.
9
+ # Just returns the passed in value if it already is an
10
+ # {ObjectInspector::Scope} object.
11
+ #
12
+ # @return [ObjectInspector::Scope]
13
+ #
14
+ # :reek:UncommunicativeMethodName
15
+ def Scope(value) # rubocop:disable Naming/MethodName
16
+ case value
17
+ when ObjectInspector::Scope
18
+ value
19
+ else
20
+ ObjectInspector::Scope.new(value)
21
21
  end
22
22
  end
23
23
  end
@@ -1,71 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectInspector
4
- # ObjectInspector::BaseFormatter is an abstract base class that interfaces
5
- # with {ObjectInspector::Inspector} objects to combine the supplied
6
- # {#identification}, {#flags}, {#info}, and {#name} strings into a friendly
7
- # "inspect" String.
8
- class BaseFormatter
9
- attr_reader :inspector
3
+ # ObjectInspector::BaseFormatter is an abstract base class that interfaces
4
+ # with {ObjectInspector::Inspector} objects to combine the supplied
5
+ # {#identification}, {#flags}, {#info}, and {#name} strings into a friendly
6
+ # "inspect" String.
7
+ class ObjectInspector::BaseFormatter
8
+ attr_reader :inspector
10
9
 
11
- # @param inspector [ObjectInspector::Inspector]
12
- def initialize(inspector)
13
- @inspector = inspector
14
- end
10
+ # @param inspector [ObjectInspector::Inspector]
11
+ def initialize(inspector)
12
+ @inspector = inspector
13
+ end
15
14
 
16
- # Perform the formatting routine.
17
- #
18
- # @return [String]
19
- def call
20
- raise NotImplementedError
21
- end
15
+ # Perform the formatting routine.
16
+ #
17
+ # @return [String]
18
+ def call
19
+ raise NotImplementedError
20
+ end
22
21
 
23
- # Delegates to {Inspector#wrapped_object_inspection_result}.
24
- #
25
- # @return [String] if given
26
- # @return [NilClass] if not given
27
- def wrapped_object_inspection_result
28
- @wrapped_object_inspection_result ||=
29
- @inspector.wrapped_object_inspection_result
30
- end
22
+ # Delegates to {Inspector#wrapped_object_inspection_result}.
23
+ #
24
+ # @return [String] if given
25
+ # @return [NilClass] if not given
26
+ def wrapped_object_inspection_result
27
+ @wrapped_object_inspection_result ||=
28
+ @inspector.wrapped_object_inspection_result
29
+ end
31
30
 
32
- # Delegates to {Inspector#identification}.
33
- #
34
- # @return [String] if given
35
- def identification
36
- @identification ||= @inspector.identification
37
- end
31
+ # Delegates to {Inspector#identification}.
32
+ #
33
+ # @return [String] if given
34
+ def identification
35
+ @identification ||= @inspector.identification
36
+ end
38
37
 
39
- # Delegates to {Inspector#flags}.
40
- #
41
- # @return [String] if given
42
- # @return [NilClass] if not given
43
- def flags
44
- @flags ||= @inspector.flags
45
- end
38
+ # Delegates to {Inspector#flags}.
39
+ #
40
+ # @return [String] if given
41
+ # @return [NilClass] if not given
42
+ def flags
43
+ @flags ||= @inspector.flags
44
+ end
46
45
 
47
- # Delegates to {Inspector#issues}.
48
- #
49
- # @return [String] if given
50
- # @return [NilClass] if not given
51
- def issues
52
- @issues ||= @inspector.issues
53
- end
46
+ # Delegates to {Inspector#issues}.
47
+ #
48
+ # @return [String] if given
49
+ # @return [NilClass] if not given
50
+ def issues
51
+ @issues ||= @inspector.issues
52
+ end
54
53
 
55
- # Delegates to {Inspector#info}.
56
- #
57
- # @return [String] if given
58
- # @return [NilClass] if not given
59
- def info
60
- @info ||= @inspector.info
61
- end
54
+ # Delegates to {Inspector#info}.
55
+ #
56
+ # @return [String] if given
57
+ # @return [NilClass] if not given
58
+ def info
59
+ @info ||= @inspector.info
60
+ end
62
61
 
63
- # Delegates to {Inspector#name}.
64
- #
65
- # @return [String] if given
66
- # @return [NilClass] if not given
67
- def name
68
- @name ||= @inspector.name
69
- end
62
+ # Delegates to {Inspector#name}.
63
+ #
64
+ # @return [String] if given
65
+ # @return [NilClass] if not given
66
+ def name
67
+ @name ||= @inspector.name
70
68
  end
71
69
  end
@@ -1,63 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectInspector
4
- # ObjectInspector::CombiningFormatter implements
5
- # {ObjectInspector::BaseFormatter} to return the standard/default inspect
6
- # output format by combining Strings.
3
+ # ObjectInspector::CombiningFormatter implements
4
+ # {ObjectInspector::BaseFormatter} to return the standard/default inspect
5
+ # output format by combining Strings.
6
+ #
7
+ # @attr (see BaseFormatter)
8
+ class ObjectInspector::CombiningFormatter < ObjectInspector::BaseFormatter
9
+ # Perform the formatting routine.
7
10
  #
8
- # @attr (see BaseFormatter)
9
- class CombiningFormatter < BaseFormatter
10
- # Perform the formatting routine.
11
- #
12
- # @return [String]
13
- def call
14
- if wrapped_object_inspection_result
15
- build_wrapped_object_string
16
- else
17
- build_string
18
- end
11
+ # @return [String]
12
+ def call
13
+ if wrapped_object_inspection_result
14
+ build_wrapped_object_string
15
+ else
16
+ build_string
19
17
  end
18
+ end
20
19
 
21
- private
20
+ private
22
21
 
23
- def build_wrapped_object_string
24
- "#{build_string} "\
22
+ def build_wrapped_object_string
23
+ "#{build_string} "\
25
24
  "#{ObjectInspector.configuration.presented_object_separator} "\
26
25
  "#{wrapped_object_inspection_result}"
27
- end
26
+ end
28
27
 
29
- def build_string
30
- "<#{combine_strings}>"
31
- end
28
+ def build_string
29
+ "<#{combine_strings}>"
30
+ end
32
31
 
33
- def combine_strings
34
- strings.join
35
- end
32
+ def combine_strings
33
+ strings.join
34
+ end
36
35
 
37
- # Override in subclasses as needed.
38
- def strings
39
- [
40
- build_identification_string,
41
- build_flags_string,
42
- build_info_string,
43
- build_name_string
44
- ].compact
45
- end
36
+ # Override in subclasses as needed.
37
+ def strings
38
+ [
39
+ build_identification_string,
40
+ build_flags_string,
41
+ build_info_string,
42
+ build_name_string,
43
+ ].compact
44
+ end
46
45
 
47
- def build_identification_string
48
- identification.to_s
49
- end
46
+ def build_identification_string
47
+ identification.to_s
48
+ end
50
49
 
51
- def build_flags_string
52
- "(#{flags.to_s.upcase})" if flags
53
- end
50
+ def build_flags_string
51
+ "(#{flags.to_s.upcase})" if flags
52
+ end
54
53
 
55
- def build_info_string
56
- " #{info}" if info
57
- end
54
+ def build_info_string
55
+ " #{info}" if info
56
+ end
58
57
 
59
- def build_name_string
60
- " :: #{name}" if name
61
- end
58
+ def build_name_string
59
+ " :: #{name}" if name
62
60
  end
63
61
  end