object_oculus 1.2.3 → 1.2.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: 13c75e4eff1e0a849c8a2162097995baa400503a112fb2c41c167a1ab91d194a
4
- data.tar.gz: da3566f45634c1718bf235c95c58ce9762e4f1c0770206a460e09c11efa79fc2
3
+ metadata.gz: f6bf6c8c81d9d8151e5da58daa71c3eb340d87fce888472a9741af82b1f8eab2
4
+ data.tar.gz: 9244bf6c9509b7516ae71ed328eb83bb1749bc55a16a3da1382152968dabcd8e
5
5
  SHA512:
6
- metadata.gz: 2489cd1b412bd62a5880de14a4452d816bef3a2e4693b482a8e1ffaae6db969854d52a027396c7d641028b9bd2174f7ea73136877a7f34d3a2b29dd0c6d6cdde
7
- data.tar.gz: 3ed6a105543d05053b0ca088824e4b83ceffbd1785694260992dd17cb45b9e84cbedc1d4409cbc7daf2873beb2895d3e2bd15a9e42954b2a64fe6f555630e2cb
6
+ metadata.gz: db7b2a5fa81503cf677e221b05a332f6b9c2209ef538e0c1402c530f23e9270345f6db2c3498e269ace001eb3cb489337d8168149288a1831215b79865098cef
7
+ data.tar.gz: b0a4f2751afae3dbfc7106f10856f89ce1060efd3a5701cdf6e08928486347715ce82c02edf694a45ebe040b66acea95348434738c63a5dfcc5d5756955d5b44
data/Gemfile.lock CHANGED
@@ -1,12 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- object_oculus (1.2.3)
4
+ object_oculus (1.2.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ ast (2.4.2)
9
10
  diff-lcs (1.5.1)
11
+ json (2.7.1)
12
+ language_server-protocol (3.17.0.3)
13
+ parallel (1.24.0)
14
+ parser (3.3.0.5)
15
+ ast (~> 2.4.1)
16
+ racc
17
+ racc (1.7.3)
18
+ rainbow (3.1.1)
19
+ regexp_parser (2.9.0)
20
+ rexml (3.2.6)
10
21
  rspec (3.13.0)
11
22
  rspec-core (~> 3.13.0)
12
23
  rspec-expectations (~> 3.13.0)
@@ -20,6 +31,21 @@ GEM
20
31
  diff-lcs (>= 1.2.0, < 2.0)
21
32
  rspec-support (~> 3.13.0)
22
33
  rspec-support (3.13.1)
34
+ rubocop (1.61.0)
35
+ json (~> 2.3)
36
+ language_server-protocol (>= 3.17.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.3.0.2)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml (>= 3.2.5, < 4.0)
42
+ rubocop-ast (>= 1.30.0, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 2.4.0, < 3.0)
45
+ rubocop-ast (1.31.1)
46
+ parser (>= 3.3.0.4)
47
+ ruby-progressbar (1.13.0)
48
+ unicode-display_width (2.5.0)
23
49
 
24
50
  PLATFORMS
25
51
  ruby
@@ -27,6 +53,7 @@ PLATFORMS
27
53
  DEPENDENCIES
28
54
  object_oculus!
29
55
  rspec (~> 3.0)
56
+ rubocop (~> 1.0)
30
57
 
31
58
  BUNDLED WITH
32
59
  2.5.6
@@ -9,14 +9,14 @@ module ObjectOculus
9
9
  # require "object_oculus/classic"
10
10
  #
11
11
  # or, if object_oculus is already loaded:
12
- #
12
+ #
13
13
  # ObjectOculus::Classic # which triggers object_oculus/classic to autoload
14
14
  module Classic
15
- alias :what? :what_equals
16
- alias :exactly? :whats_exactly
17
- alias :matches? :what_matches
18
- alias :works? :what_works_with
19
- alias :not_blank? :whats_not_blank_with
15
+ alias what? what_equals
16
+ alias exactly? whats_exactly
17
+ alias matches? what_matches
18
+ alias works? what_works_with
19
+ alias not_blank? whats_not_blank_with
20
20
  end
21
21
 
22
22
  class MethodFinder
@@ -24,6 +24,6 @@ module ObjectOculus
24
24
  end
25
25
  end
26
26
 
27
- class Object # :nodoc:
27
+ class Object # :nodoc:
28
28
  include ObjectOculus::Classic
29
29
  end
@@ -4,7 +4,7 @@ module ObjectOculus
4
4
  # Does nothing (instead of writing to an IO stream)
5
5
  def write(*args)
6
6
  end
7
- alias :print :write
8
- alias :puts :write
7
+ alias print write
8
+ alias puts write
9
9
  end
10
10
  end
@@ -21,7 +21,8 @@ module ObjectOculus
21
21
 
22
22
  # An override of Methods#show_methods that passes the object stored in <tt>@object</tt> instead of
23
23
  # +self+
24
- def show_methods(expected_result, opts = {}, *args, &block) # :doc:
24
+ # :doc:
25
+ def show_methods(expected_result, opts = {}, *args, &)
25
26
  @args = args unless args.empty?
26
27
  MethodFinder.show(@object, expected_result, opts, *@args)
27
28
  end
@@ -3,16 +3,37 @@ module ObjectOculus
3
3
  # values with an expected result. ny matches will then be pretty printed to the console.
4
4
  class MethodFinder
5
5
  # A list of symbols indicated which methods to always ignore
6
- @@blacklist = %w(daemonize debug debugger display ed emacs exec exit! fork mate nano sleep
7
- stub stub! stub_chain syscall system unstub unstub! vi vim).map(&:to_sym)
6
+ @@blacklist = %w[
7
+ daemonize
8
+ debug
9
+ debugger
10
+ display
11
+ ed
12
+ emacs
13
+ exec
14
+ exit!
15
+ fork
16
+ mate
17
+ nano
18
+ sleep
19
+ stub
20
+ stub!
21
+ stub_chain
22
+ syscall
23
+ system
24
+ unstub
25
+ unstub!
26
+ vi
27
+ vim
28
+ ].map(&:to_sym)
8
29
  @@blacklist += Methods.instance_methods
9
30
 
10
31
  # A list of symbols for infix operators for which Ruby has special syntax
11
- @@infixes = %w(+ - * / % ** == != =~ !~ !=~ > < >= <= <=> === & | ^ << >>).map(&:to_sym)
12
-
32
+ @@infixes = %w[+ - * / % ** == != =~ !~ !=~ > < >= <= <=> === & | ^ << >>].map(&:to_sym)
33
+
13
34
  # A list of symbols for prefix operators for which Ruby has special syntax
14
- @@prefixes = %w(+@ -@ ~ !).map(&:to_sym)
15
-
35
+ @@prefixes = %w[+@ -@ ~ !].map(&:to_sym)
36
+
16
37
  class << self
17
38
  # Builds a lambda for checking against the provided +expected_result+ given a hash of options.
18
39
  # Given the value of a method, the result of this lambda will determine whether that method
@@ -37,7 +58,7 @@ module ObjectOculus
37
58
  if opts[:exclude_blank]
38
59
  ->(value) { !value.nil? && !(value.respond_to?(:empty?) && value.empty?) }
39
60
  else
40
- ->(value) { true }
61
+ ->(_value) { true }
41
62
  end
42
63
  else
43
64
  ->(value) { expected_result == value }
@@ -46,7 +67,7 @@ module ObjectOculus
46
67
 
47
68
  # Find all methods on +an_object+ which, when called with +args+ return +expected_result+
48
69
  def find(an_object, expected_result, opts = {}, *args, &block)
49
- check_result = build_check_lambda(expected_result, opts)
70
+ check_result = build_check_lambda(expected_result, opts)
50
71
 
51
72
  # Prevent any writing to the terminal
52
73
  stdout, stderr = $stdout, $stderr
@@ -60,33 +81,32 @@ module ObjectOculus
60
81
  methods.select! { |n| an_object.method(n).arity <= args.size && !@@blacklist.include?(n) }
61
82
 
62
83
  # Collect all methods equaling the expected result
63
- results = methods.inject({}) do |res, name|
84
+ results = methods.each_with_object({}) do |name, res|
64
85
  stdout.print ""
65
86
  begin
66
87
  value = an_object.clone.method(name).call(*args, &block)
67
88
  res[name] = value if check_result.call(value)
68
- rescue
89
+ rescue StandardError
69
90
  end
70
- res
71
91
  end
72
92
 
73
93
  # Restore printing to the terminal
74
94
  $stdout, $stderr = stdout, stderr if restore_std
75
95
  results
76
96
  end
77
-
97
+
78
98
  # Pretty prints the results of #find
79
- def show(an_object, expected_result, opts = {}, *args, &block)
99
+ def show(an_object, expected_result, opts = {}, *args, &)
80
100
  opts = {
81
101
  exclude_blank: false,
82
- force_exact: false,
83
- force_regex: false,
84
- show_all: false
102
+ force_exact: false,
103
+ force_regex: false,
104
+ show_all: false,
85
105
  }.merge(opts)
86
106
 
87
- found = find(an_object, expected_result, opts, *args, &block)
107
+ found = find(an_object, expected_result, opts, *args, &)
88
108
  prettified = prettify_found(an_object, found, *args)
89
- max_length = prettified.map { |k, v| k.length }.max
109
+ max_length = prettified.map { |k, _v| k.length }.max
90
110
 
91
111
  prettified.each { |k, v| puts "#{k.ljust max_length} == #{v}" }
92
112
 
@@ -98,14 +118,14 @@ module ObjectOculus
98
118
  # Pretty prints a method depending on whether it's an operator, has arguments, is array/hash
99
119
  # syntax, etc.
100
120
  def prettify_found(an_object, found, *args)
101
- args = args.map { |a| a.inspect }.join(", ")
121
+ args = args.map(&:inspect).join(", ")
102
122
  pretty_object = truncate_inspect(an_object, to: 40)
103
123
 
104
124
  found.map do |key, value|
105
125
  pretty_key = if @@infixes.include?(key)
106
126
  "#{pretty_object} #{key} #{args}"
107
127
  elsif @@prefixes.include?(key)
108
- "#{key.to_s.sub /\@$/, ""}#{pretty_object}"
128
+ "#{key.to_s.sub(/@$/, '')}#{pretty_object}"
109
129
  elsif key == :[]
110
130
  "#{pretty_object}[#{args}]"
111
131
  elsif args != ""
@@ -117,8 +137,8 @@ module ObjectOculus
117
137
  pretty_value =
118
138
  begin
119
139
  truncate_inspect(value, to: 120)
120
- rescue => ex
121
- ex.class
140
+ rescue StandardError => e
141
+ e.class
122
142
  end
123
143
 
124
144
  [pretty_key, pretty_value]
@@ -129,14 +149,14 @@ module ObjectOculus
129
149
  # provided <tt>to:</tt> argument if necessary
130
150
  def truncate_inspect(object, opts = {})
131
151
  max_length = opts[:to] || 80
132
- full = object.inspect
152
+ full = object.inspect
133
153
 
134
154
  if full.length > max_length
135
- available_length = max_length - 5 # to account for the " ... "
136
- left_cutoff = available_length * 2 / 3
137
- right_cutoff = available_length - left_cutoff - 1
155
+ available_length = max_length - 5 # to account for the " ... "
156
+ left_cutoff = available_length * 2 / 3
157
+ right_cutoff = available_length - left_cutoff - 1
138
158
 
139
- "#{full[0..left_cutoff]} ... #{full[-right_cutoff..-1]}"
159
+ "#{full[0..left_cutoff]} ... #{full[-right_cutoff..]}"
140
160
  else
141
161
  full
142
162
  end
@@ -7,7 +7,7 @@ module ObjectOculus
7
7
  # # => 5 + 1 == 6
8
8
  def given(*args)
9
9
  if frozen?
10
- FrozenSection.new self, args: args
10
+ FrozenSection.new(self, args:)
11
11
  else
12
12
  @args = args
13
13
  self
@@ -16,33 +16,33 @@ module ObjectOculus
16
16
 
17
17
  # Outputs a list of methods and their values that equal an +expected_result+, allowing for some
18
18
  # coercion (e.g. <tt>5 == 5.0</tt>)
19
- def what_equals(expected_result, *args, &block)
20
- show_methods expected_result, {}, *args, &block
19
+ def what_equals(expected_result, ...)
20
+ show_methods(expected_result, {}, ...)
21
21
  end
22
22
 
23
23
  # Outputs a list of methods and their values that exactly equal an +expected_result+
24
- def whats_exactly(expected_result, *args, &block)
25
- show_methods expected_result, { force_exact: true }, *args, &block
24
+ def whats_exactly(expected_result, ...)
25
+ show_methods(expected_result, { force_exact: true }, ...)
26
26
  end
27
27
 
28
28
  # Outputs a list of methods and their values that match an +expected_result+, which is coerced
29
29
  # into a regular expression if it's not already one
30
- def what_matches(expected_result, *args, &block)
31
- show_methods expected_result, { force_regex: true }, *args, &block
30
+ def what_matches(expected_result, ...)
31
+ show_methods(expected_result, { force_regex: true }, ...)
32
32
  end
33
33
 
34
34
  # Outputs a list of all methods and their values
35
- def what_works_with(*args, &block)
36
- show_methods nil, { show_all: true }, *args, &block
35
+ def what_works_with(...)
36
+ show_methods(nil, { show_all: true }, ...)
37
37
  end
38
- alias :what_works :what_works_with
38
+ alias what_works what_works_with
39
39
 
40
40
  # Outputs a list of all methods and their values, provided they are not blank (nil, false,
41
41
  # undefined, empty)
42
- def whats_not_blank_with(*args, &block)
43
- show_methods nil, { show_all: true, exclude_blank: true }, *args, &block
42
+ def whats_not_blank_with(...)
43
+ show_methods(nil, { show_all: true, exclude_blank: true }, ...)
44
44
  end
45
- alias :whats_not_blank :whats_not_blank_with
45
+ alias whats_not_blank whats_not_blank_with
46
46
 
47
47
  # The list of all methods unique to an object
48
48
  def unique_methods
@@ -51,14 +51,13 @@ module ObjectOculus
51
51
 
52
52
  # Lists all methods available to the object by ancestor
53
53
  def methods_by_ancestor
54
- ([self] + self.class.ancestors).inject({}) do |result, object|
54
+ ([self] + self.class.ancestors).each_with_object({}) do |object, result|
55
55
  result[object] = object.unique_methods
56
- result
57
56
  end
58
57
  end
59
58
 
60
59
  # Make sure cloning doesn't cause anything to fail via type errors
61
- alias_method :__clone__, :clone
60
+ alias __clone__ clone
62
61
 
63
62
  # Adds in a type error check to the default Object#clone method to prevent any interruptions while
64
63
  # checking methods. If a TypeError is encountered, +self+ is returned
@@ -72,9 +71,10 @@ module ObjectOculus
72
71
 
73
72
  # Called by all of the +what_+ methods, this tells MethodFinder to output the result for any methods
74
73
  # matching an +expected_result+ for the #given arguments
75
- def show_methods(expected_result, opts = {}, *args, &block) # :doc:
74
+ # :doc:
75
+ def show_methods(expected_result, opts = {}, *args, &)
76
76
  @args = args unless args.empty?
77
- MethodFinder.show(self, expected_result, opts, *@args, &block)
77
+ MethodFinder.show(self, expected_result, opts, *@args, &)
78
78
  end
79
79
  end
80
80
  end
@@ -1,4 +1,4 @@
1
1
  module ObjectOculus
2
2
  # The current version
3
- VERSION = "1.2.3"
3
+ VERSION = "1.2.4"
4
4
  end
data/lib/object_oculus.rb CHANGED
@@ -1,37 +1,37 @@
1
- # object_oculus enables you to determine what methods can be called on an object that return a given
2
- # value
3
- #
4
- # === Some credits from Dr. Nic
5
- #
6
- # Code this version is based on: {Andrew
7
- # Birkett's}[http://www.nobugs.org/developer/ruby/method_finder.html]
8
- #
9
- # Improvements from Why's blog entry:
10
- # * +what?+ - Why
11
- # * <tt>@@blacklist</tt> - llasram
12
- # * +clone+ alias - Daniel Schierbeck
13
- # * <tt>$stdout</tt> redirect - Why
14
- #
15
- # {Improvements from Nikolas Coukouma}[http://atrustheotaku.livejournal.com/339449.html]
16
- # * Varargs and block support
17
- # * Improved catching
18
- # * Redirecting <tt>$stdout</tt> and <tt>$stderr</tt> (independently of Why)
19
- #
20
- # {A version posted in 2002 by Steven
21
- # Grady}[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32844]
22
- #
23
- # David Tran's versions:
24
- # * Simple[http://www.doublegifts.com/pub/ruby/methodfinder.rb.html]
25
- # * {Checks permutations of arguments}[http://www.doublegifts.com/pub/ruby/methodfinder2.rb.html]
26
- module ObjectOculus
27
- autoload :Classic, "object_oculus/classic"
28
- autoload :DummyOut, "object_oculus/dummy_out"
29
- autoload :FrozenSection, "object_oculus/frozen_section"
30
- autoload :MethodFinder, "object_oculus/method_finder"
31
- autoload :Methods, "object_oculus/methods"
32
- autoload :VERSION, "object_oculus/version"
33
- end
34
-
35
- class Object # :nodoc:
36
- include ObjectOculus::Methods
37
- end
1
+ # object_oculus enables you to determine what methods can be called on an object that return a given
2
+ # value
3
+ #
4
+ # === Some credits from Dr. Nic
5
+ #
6
+ # Code this version is based on: {Andrew
7
+ # Birkett's}[http://www.nobugs.org/developer/ruby/method_finder.html]
8
+ #
9
+ # Improvements from Why's blog entry:
10
+ # * +what?+ - Why
11
+ # * <tt>@@blacklist</tt> - llasram
12
+ # * +clone+ alias - Daniel Schierbeck
13
+ # * <tt>$stdout</tt> redirect - Why
14
+ #
15
+ # {Improvements from Nikolas Coukouma}[http://atrustheotaku.livejournal.com/339449.html]
16
+ # * Varargs and block support
17
+ # * Improved catching
18
+ # * Redirecting <tt>$stdout</tt> and <tt>$stderr</tt> (independently of Why)
19
+ #
20
+ # {A version posted in 2002 by Steven
21
+ # Grady}[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32844]
22
+ #
23
+ # David Tran's versions:
24
+ # * Simple[http://www.doublegifts.com/pub/ruby/methodfinder.rb.html]
25
+ # * {Checks permutations of arguments}[http://www.doublegifts.com/pub/ruby/methodfinder2.rb.html]
26
+ module ObjectOculus
27
+ autoload :Classic, "object_oculus/classic"
28
+ autoload :DummyOut, "object_oculus/dummy_out"
29
+ autoload :FrozenSection, "object_oculus/frozen_section"
30
+ autoload :MethodFinder, "object_oculus/method_finder"
31
+ autoload :Methods, "object_oculus/methods"
32
+ autoload :VERSION, "object_oculus/version"
33
+ end
34
+
35
+ class Object # :nodoc:
36
+ include ObjectOculus::Methods
37
+ end
@@ -1,22 +1,24 @@
1
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
2
  require "object_oculus/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "object_oculus"
6
- s.authors = ["Jason Cheong-Kee-You", "Bryan McKelvey", "Dr Nic Williams"]
7
- s.email = "j.chunky@gmail.com"
8
- s.homepage = "https://github.com/jchunky/object_oculus"
9
- s.licenses = ['MIT']
10
- s.platform = Gem::Platform::RUBY
11
- s.version = ObjectOculus::VERSION
12
- s.summary = "Rapidly explore an object's API in 'irb'"
5
+ s.name = "object_oculus"
6
+ s.authors = ["Jason Cheong-Kee-You", "Bryan McKelvey", "Dr Nic Williams"]
7
+ s.email = "j.chunky@gmail.com"
8
+ s.homepage = "https://github.com/jchunky/object_oculus"
9
+ s.licenses = ["MIT"]
10
+ s.platform = Gem::Platform::RUBY
11
+ s.version = ObjectOculus::VERSION
12
+ s.summary = "Rapidly explore an object's API in 'irb'"
13
13
  s.description = <<~DESCRIPTION
14
14
  ObjectOculus is a ruby tool for viewing all of an object's methods and seeing what those
15
15
  methods return. ObjectOculus can be used in 'irb' to rapidly explore an object's API.
16
16
  DESCRIPTION
17
17
 
18
- s.files = `git ls-files`.split("\n")
18
+ s.files = `git ls-files`.split("\n")
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency "rspec", "~> 3.0"
22
+ s.add_development_dependency "rubocop", "~> 1.0"
23
+ s.metadata["rubygems_mfa_required"] = "true"
22
24
  end
@@ -20,4 +20,4 @@ RSpec.describe FrozenSection do
20
20
  expect(@string.given(1)).to be_a(FrozenSection)
21
21
  end
22
22
  end
23
- end
23
+ end
data/spec/methods_spec.rb CHANGED
@@ -57,4 +57,4 @@ RSpec.describe Methods do
57
57
  end
58
58
  end
59
59
  end
60
- end
60
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,5 +3,5 @@ require "object_oculus"
3
3
  include ObjectOculus
4
4
 
5
5
  RSpec.configure do |config|
6
- config.deprecation_stream = '/dev/null'
6
+ config.deprecation_stream = "/dev/null"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_oculus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Cheong-Kee-You
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rubocop
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
29
43
  description: |
30
44
  ObjectOculus is a ruby tool for viewing all of an object's methods and seeing what those
31
45
  methods return. ObjectOculus can be used in 'irb' to rapidly explore an object's API.
@@ -55,7 +69,8 @@ files:
55
69
  homepage: https://github.com/jchunky/object_oculus
56
70
  licenses:
57
71
  - MIT
58
- metadata: {}
72
+ metadata:
73
+ rubygems_mfa_required: 'true'
59
74
  post_install_message:
60
75
  rdoc_options: []
61
76
  require_paths: