rbr 0.2.0 → 0.3.0

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: 8f991cd863713e0995b19ec6dd66772030342e9af5ef18441ed14afe7c68a24d
4
- data.tar.gz: a12bb9d633f5b33dbd78034a26915e4168deefa306d5ec567adf672b02d4cf34
3
+ metadata.gz: 5432cecc06454f1661bfaffc004f86cea0847830fc2b515041d6bc7eef95c01d
4
+ data.tar.gz: 4b647a9113e3c7c722dac052f818046214fcf4608800630d93b1e22bf9539563
5
5
  SHA512:
6
- metadata.gz: 36c06cff179b606e84e217adfc1233f0fe9b817acb749c780230959445b7585ac6a39ac41e3ddef4a58399935d3ad8602b51fe1d3a5d13e9ea90e7251ff01f68
7
- data.tar.gz: 76040e738fb9c97400836106c368eafa9e1a93112622d9f13ef86f77f9cd9d54a477a4bb9f42c7dc5f237c14a99ea4cbe3adfe4d767b354cbd84e3d6a547a80f
6
+ metadata.gz: f6250ccbdc34e10bea0c6830a8c3d0c6e5d3559135c614d4b837f8497d89c512a4fe34aca464cf1add7793d82f6715f0cbdb9dad4b5824143cff8acf0e267f40
7
+ data.tar.gz: ccef9e8f51d646c6c74dcda32078b462f98e3651aea6c43e58739f981a82d598b38dd0c3401a76b4b7983f5a8bcfb18872b9c200a18065099dde7031e7b43454
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbr (0.2.0)
4
+ rbr (0.3.0)
5
5
  parser
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ast (2.4.0)
10
+ ast (2.4.1)
11
11
  coderay (1.1.3)
12
12
  method_source (1.0.0)
13
13
  minitest (5.14.1)
14
- parser (2.7.1.3)
15
- ast (~> 2.4.0)
14
+ parser (2.7.1.4)
15
+ ast (~> 2.4.1)
16
16
  pry (0.13.1)
17
17
  coderay (~> 1.1)
18
18
  method_source (~> 1.0)
data/README.md CHANGED
@@ -5,50 +5,76 @@ constructs.
5
5
 
6
6
  ## Usage examples
7
7
 
8
+ assignment to an lvalue named `@author`
9
+
8
10
  ```sh
9
- # assignment to an lvalue named `@author`
10
11
  $ rbr assignment :@author test/fixtures/book.rb
11
- 5: @author = author
12
+ test/fixtures/book.rb:5: @author = author
13
+ ```
12
14
 
13
- # int or float
15
+ int or float with value `5`
16
+
17
+ ```sh
14
18
  $ rbr number 5 test/fixtures/book.rb
15
- 12: 5
19
+ test/fixtures/book.rb:12: 5
20
+ ```
21
+
22
+ string matching the pattern `/ring/`
16
23
 
17
- # string
24
+ ```sh
18
25
  $ rbr string ring test/fixtures/book.rb
19
- 13: "a string!"
26
+ test/fixtures/book.rb:13: "a string!"
27
+ ```
28
+
29
+ literal (int, float, or string) with the value `5`
20
30
 
21
- # a literal (int, float, or string)
31
+ ```sh
22
32
  $ rbr literal 5 test/fixtures/book.rb
23
- 12: 5
24
- 49: "5"
33
+ test/fixtures/book.rb:12: 5
34
+ test/fixtures/book.rb:49: "5"
35
+ ```
36
+
37
+ comment matching the pattern `/great/`
25
38
 
26
- # comments matching the pattern /great/
39
+ ```sh
27
40
  $ rbr comment great test/fixtures/book.rb
28
- 1: # This is a great class
41
+ test/fixtures/book.rb:1: # This is a great class
42
+ ```
43
+
44
+ call of a method named `great_method`
29
45
 
30
- # find all calls of a method named `great_method`
46
+ ```sh
31
47
  $ rbr method_call :great_method test/fixtures/book.rb
32
- 27: book.update!(title: "Great Title")
33
- 50: book.send(:update!, title: "Great Title")
48
+ test/fixtures/book.rb:27: book.great_method
49
+ test/fixtures/book.rb:50: book.send(:great_method)
50
+ ```
34
51
 
35
- # statements that update an ActiveRecord model attribute named `title`
52
+ statement that updates an ActiveRecord model attribute named `title`
53
+
54
+ ```sh
36
55
  $ rbr ar_update :title test/fixtures/book.rb
37
- 21: book.title = "Great Title"
38
- 27: book.update!(title: "Great Title")
39
- 31: book.send(:update_column, :title, "Great Title")
56
+ test/fixtures/book.rb:21: book.title = "Great Title"
57
+ test/fixtures/book.rb:27: book.update!(title: "Great Title")
58
+ test/fixtures/book.rb:31: book.send(:update_column, :title, "Great Title")
40
59
  ```
41
60
 
42
61
  rbr is the wrong tool for the following situations:
43
62
 
63
+ appearance of the string "author" in the source
64
+
44
65
  ```sh
45
- # find any appearance of the string "author" in the source
46
66
  $ grep "author"
67
+ ```
68
+
69
+ symbol named :author
47
70
 
48
- # find a symbol named :author
71
+ ```sh
49
72
  $ grep ":author"
73
+ ```
74
+
75
+ definition of any function named "publish"
50
76
 
51
- # find the definition of any function named "publish"
77
+ ```sh
52
78
  $ grep "def publish"
53
79
  ```
54
80
 
@@ -14,21 +14,32 @@ module Rbr
14
14
  end
15
15
 
16
16
  def start
17
- filenames.each do |filename|
18
- root, comments = Parser::CurrentRuby.parse_file_with_comments(filename)
17
+ matching_nodes.each do |filename, nodes|
18
+ nodes.each { |node| puts "#{filename}:#{node.pretty_print}" }
19
+ end
20
+ end
19
21
 
20
- matching_nodes = Query.new(@matcher, @condition).run(root, comments)
22
+ def matching_nodes
23
+ filenames.map do |filename|
24
+ root, comments = Parser::CurrentRuby.parse_file_with_comments(filename)
21
25
 
22
- matching_nodes.each { |node| puts node.pretty_print }
26
+ [filename, Query.new(@matcher, @condition).run(root, comments)]
23
27
  rescue EncodingError
24
28
  warn "# Encoding error parsing #{filename}"
25
- end
29
+ [filename, []]
30
+ end.to_h
26
31
  end
27
32
 
28
33
  def filenames
29
- ARGV[2..].map { |arg| expand_path(arg) }
30
- .flatten
31
- .select { |filename| File.file?(filename) }
34
+ pattern = if ARGV.count > 2
35
+ ARGV[2..]
36
+ else
37
+ ["."]
38
+ end
39
+
40
+ pattern.map { |arg| expand_path(arg) }
41
+ .flatten
42
+ .select { |filename| File.file?(filename) }
32
43
  end
33
44
 
34
45
  def expand_path(path)
@@ -39,7 +50,7 @@ module Rbr
39
50
  end
40
51
 
41
52
  def check_arg_count
42
- return true if ARGV.count >= 3
53
+ return true if ARGV.count >= 2
43
54
 
44
55
  warn <<~USAGE
45
56
  Usage:
@@ -33,7 +33,7 @@ module Rbr
33
33
 
34
34
  # Node is a literal int, float, or string
35
35
  def self.literal(node, value)
36
- number(node, value) || str(node, value)
36
+ number(node, value) || string(node, value)
37
37
  end
38
38
 
39
39
  # Node is a literal int or float
@@ -51,7 +51,7 @@ module Rbr
51
51
  end
52
52
 
53
53
  # Node is a string
54
- def self.str(node, pattern)
54
+ def self.string(node, pattern)
55
55
  pattern &&
56
56
  node.str? &&
57
57
  node.any_descendant_matches?(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rbr
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Lebow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-13 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser