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 +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +47 -21
- data/lib/rbr/cli.rb +20 -9
- data/lib/rbr/matchers.rb +2 -2
- data/lib/rbr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5432cecc06454f1661bfaffc004f86cea0847830fc2b515041d6bc7eef95c01d
|
4
|
+
data.tar.gz: 4b647a9113e3c7c722dac052f818046214fcf4608800630d93b1e22bf9539563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6250ccbdc34e10bea0c6830a8c3d0c6e5d3559135c614d4b837f8497d89c512a4fe34aca464cf1add7793d82f6715f0cbdb9dad4b5824143cff8acf0e267f40
|
7
|
+
data.tar.gz: ccef9e8f51d646c6c74dcda32078b462f98e3651aea6c43e58739f981a82d598b38dd0c3401a76b4b7983f5a8bcfb18872b9c200a18065099dde7031e7b43454
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbr (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.
|
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.
|
15
|
-
ast (~> 2.4.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
46
|
+
```sh
|
31
47
|
$ rbr method_call :great_method test/fixtures/book.rb
|
32
|
-
27: book.
|
33
|
-
50: book.send(:
|
48
|
+
test/fixtures/book.rb:27: book.great_method
|
49
|
+
test/fixtures/book.rb:50: book.send(:great_method)
|
50
|
+
```
|
34
51
|
|
35
|
-
|
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
|
-
|
71
|
+
```sh
|
49
72
|
$ grep ":author"
|
73
|
+
```
|
74
|
+
|
75
|
+
definition of any function named "publish"
|
50
76
|
|
51
|
-
|
77
|
+
```sh
|
52
78
|
$ grep "def publish"
|
53
79
|
```
|
54
80
|
|
data/lib/rbr/cli.rb
CHANGED
@@ -14,21 +14,32 @@ module Rbr
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def start
|
17
|
-
|
18
|
-
|
17
|
+
matching_nodes.each do |filename, nodes|
|
18
|
+
nodes.each { |node| puts "#{filename}:#{node.pretty_print}" }
|
19
|
+
end
|
20
|
+
end
|
19
21
|
|
20
|
-
|
22
|
+
def matching_nodes
|
23
|
+
filenames.map do |filename|
|
24
|
+
root, comments = Parser::CurrentRuby.parse_file_with_comments(filename)
|
21
25
|
|
22
|
-
|
26
|
+
[filename, Query.new(@matcher, @condition).run(root, comments)]
|
23
27
|
rescue EncodingError
|
24
28
|
warn "# Encoding error parsing #{filename}"
|
25
|
-
|
29
|
+
[filename, []]
|
30
|
+
end.to_h
|
26
31
|
end
|
27
32
|
|
28
33
|
def filenames
|
29
|
-
ARGV
|
30
|
-
|
31
|
-
|
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 >=
|
53
|
+
return true if ARGV.count >= 2
|
43
54
|
|
44
55
|
warn <<~USAGE
|
45
56
|
Usage:
|
data/lib/rbr/matchers.rb
CHANGED
@@ -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) ||
|
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.
|
54
|
+
def self.string(node, pattern)
|
55
55
|
pattern &&
|
56
56
|
node.str? &&
|
57
57
|
node.any_descendant_matches?(
|
data/lib/rbr/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|