querly 0.16.0 → 1.0.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/CHANGELOG.md +5 -0
- data/lib/querly.rb +1 -0
- data/lib/querly/cli.rb +27 -9
- data/lib/querly/cli/console.rb +7 -3
- data/lib/querly/cli/find.rb +8 -4
- data/lib/querly/script_enumerator.rb +17 -4
- data/lib/querly/version.rb +1 -1
- data/querly.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a365f3cf29cb25703707662a6102e79eb0b838386d1a792b8522ba4dbd45be6
|
4
|
+
data.tar.gz: 24773a3bf4817d76f29e5c96ab02c39650c29a5dac5e712ae58d821eed1b2906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a40df07387dce70a282203e8e30daf5794f5da9f90ec20dc61516a750b3b72aaf77b605ee85707f9f257f5d955f2cc4815742cde27052f762746601b66d55e5
|
7
|
+
data.tar.gz: 53d33483e9d501d8954ad0640a4990bf919eb6f93452a186cb4e593d22dbbbb101c79a60e5905c281703d4887664e87bec0b3d5d3fc602bfd9607d2bd61d916c
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.0.0 (2019-7-19)
|
6
|
+
|
7
|
+
* Add `--config` option for `find` and `console` [#67](https://github.com/soutaro/querly/pull/67)
|
8
|
+
* Improve preprocessor performance by processing concurrently [#68](https://github.com/soutaro/querly/pull/68)
|
9
|
+
|
5
10
|
## 0.16.0 (2019-04-23)
|
6
11
|
|
7
12
|
* Support string literal pattern (@pocke) [#64](https://github.com/soutaro/querly/pull/64)
|
data/lib/querly.rb
CHANGED
data/lib/querly/cli.rb
CHANGED
@@ -12,6 +12,7 @@ module Querly
|
|
12
12
|
option :root
|
13
13
|
option :format, default: "text", type: :string, enum: %w(text json)
|
14
14
|
option :rule, type: :string
|
15
|
+
option :threads, default: Parallel.processor_count, type: :numeric
|
15
16
|
def check(*paths)
|
16
17
|
require 'querly/cli/formatter'
|
17
18
|
|
@@ -23,6 +24,8 @@ module Querly
|
|
23
24
|
end
|
24
25
|
formatter.start
|
25
26
|
|
27
|
+
threads = Integer(options[:threads])
|
28
|
+
|
26
29
|
begin
|
27
30
|
unless config_path.file?
|
28
31
|
STDERR.puts <<-Message
|
@@ -32,20 +35,15 @@ Specify configuration file by --config option.
|
|
32
35
|
exit 1
|
33
36
|
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
config = begin
|
39
|
-
yaml = YAML.load(config_path.read)
|
40
|
-
Config.load(yaml, config_path: config_path, root_dir: root_path, stderr: STDERR)
|
38
|
+
begin
|
39
|
+
config = config(root_option: options[:root])
|
41
40
|
rescue => exn
|
42
41
|
formatter.config_error config_path, exn
|
43
|
-
exit 1
|
44
42
|
end
|
45
43
|
|
46
44
|
analyzer = Analyzer.new(config: config, rule: options[:rule])
|
47
45
|
|
48
|
-
ScriptEnumerator.new(paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) }, config: config).each do |path, script|
|
46
|
+
ScriptEnumerator.new(paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) }, config: config, threads: threads).each do |path, script|
|
49
47
|
case script
|
50
48
|
when Script
|
51
49
|
analyzer.scripts << script
|
@@ -67,6 +65,8 @@ Specify configuration file by --config option.
|
|
67
65
|
end
|
68
66
|
|
69
67
|
desc "console [paths]", "Start console for given paths"
|
68
|
+
option :config, default: "querly.yml"
|
69
|
+
option :threads, default: Parallel.processor_count, type: :numeric
|
70
70
|
def console(*paths)
|
71
71
|
require 'querly/cli/console'
|
72
72
|
home_path = if (path = ENV["QUERLY_HOME"])
|
@@ -75,21 +75,32 @@ Specify configuration file by --config option.
|
|
75
75
|
Pathname(Dir.home) + ".querly"
|
76
76
|
end
|
77
77
|
home_path.mkdir unless home_path.exist?
|
78
|
+
config = config_path.file? ? config(root_option: nil) : nil
|
79
|
+
threads = Integer(options[:threads])
|
78
80
|
|
79
81
|
Console.new(
|
80
82
|
paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) },
|
81
83
|
history_path: home_path + "history",
|
82
|
-
history_size: ENV["QUERLY_HISTORY_SIZE"]&.to_i || 1_000_000
|
84
|
+
history_size: ENV["QUERLY_HISTORY_SIZE"]&.to_i || 1_000_000,
|
85
|
+
config: config,
|
86
|
+
threads: threads
|
83
87
|
).start
|
84
88
|
end
|
85
89
|
|
86
90
|
desc "find pattern [paths]", "Find for the pattern in given paths"
|
91
|
+
option :config, default: "querly.yml"
|
92
|
+
option :threads, default: Parallel.processor_count, type: :numeric
|
87
93
|
def find(pattern, *paths)
|
88
94
|
require 'querly/cli/find'
|
89
95
|
|
96
|
+
config = config_path.file? ? config(root_option: nil) : nil
|
97
|
+
threads = Integer(options[:threads])
|
98
|
+
|
90
99
|
Find.new(
|
91
100
|
pattern: pattern,
|
92
101
|
paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) },
|
102
|
+
config: config,
|
103
|
+
threads: threads
|
93
104
|
).start
|
94
105
|
end
|
95
106
|
|
@@ -125,6 +136,13 @@ Specify configuration file by --config option.
|
|
125
136
|
|
126
137
|
private
|
127
138
|
|
139
|
+
def config(root_option:)
|
140
|
+
root_path = root_option ? Pathname(root_option).realpath : config_path.parent.realpath
|
141
|
+
|
142
|
+
yaml = YAML.load(config_path.read)
|
143
|
+
Config.load(yaml, config_path: config_path, root_dir: root_path, stderr: STDERR)
|
144
|
+
end
|
145
|
+
|
128
146
|
def config_path
|
129
147
|
[Pathname(options[:config]),
|
130
148
|
Pathname("querly.yaml")].compact.find(&:file?) || Pathname(options[:config])
|
data/lib/querly/cli/console.rb
CHANGED
@@ -8,13 +8,17 @@ module Querly
|
|
8
8
|
attr_reader :paths
|
9
9
|
attr_reader :history_path
|
10
10
|
attr_reader :history_size
|
11
|
+
attr_reader :config
|
11
12
|
attr_reader :history
|
13
|
+
attr_reader :threads
|
12
14
|
|
13
|
-
def initialize(paths:, history_path:, history_size:)
|
15
|
+
def initialize(paths:, history_path:, history_size:, config: nil, threads:)
|
14
16
|
@paths = paths
|
15
17
|
@history_path = history_path
|
16
18
|
@history_size = history_size
|
19
|
+
@config = config
|
17
20
|
@history = []
|
21
|
+
@threads = threads
|
18
22
|
end
|
19
23
|
|
20
24
|
def start
|
@@ -42,9 +46,9 @@ Querly #{VERSION}, interactive console
|
|
42
46
|
def analyzer
|
43
47
|
return @analyzer if @analyzer
|
44
48
|
|
45
|
-
@analyzer = Analyzer.new(config:
|
49
|
+
@analyzer = Analyzer.new(config: config, rule: nil)
|
46
50
|
|
47
|
-
ScriptEnumerator.new(paths: paths, config:
|
51
|
+
ScriptEnumerator.new(paths: paths, config: config, threads: threads).each do |path, script|
|
48
52
|
case script
|
49
53
|
when Script
|
50
54
|
@analyzer.scripts << script
|
data/lib/querly/cli/find.rb
CHANGED
@@ -7,10 +7,14 @@ module Querly
|
|
7
7
|
|
8
8
|
attr_reader :pattern_str
|
9
9
|
attr_reader :paths
|
10
|
+
attr_reader :config
|
11
|
+
attr_reader :threads
|
10
12
|
|
11
|
-
def initialize(pattern:, paths:)
|
13
|
+
def initialize(pattern:, paths:, config: nil, threads:)
|
12
14
|
@pattern_str = pattern
|
13
15
|
@paths = paths
|
16
|
+
@config = config
|
17
|
+
@threads = threads
|
14
18
|
end
|
15
19
|
|
16
20
|
def start
|
@@ -36,7 +40,7 @@ module Querly
|
|
36
40
|
puts "#{count} results"
|
37
41
|
rescue => exn
|
38
42
|
STDOUT.puts Rainbow("Error: #{exn}").red
|
39
|
-
|
43
|
+
STDOUT.puts "pattern: #{pattern_str}"
|
40
44
|
STDOUT.puts "Backtrace:"
|
41
45
|
STDOUT.puts format_backtrace(exn.backtrace)
|
42
46
|
end
|
@@ -48,9 +52,9 @@ module Querly
|
|
48
52
|
def analyzer
|
49
53
|
return @analyzer if @analyzer
|
50
54
|
|
51
|
-
@analyzer = Analyzer.new(config:
|
55
|
+
@analyzer = Analyzer.new(config: config, rule: nil)
|
52
56
|
|
53
|
-
ScriptEnumerator.new(paths: paths, config:
|
57
|
+
ScriptEnumerator.new(paths: paths, config: config, threads: threads).each do |path, script|
|
54
58
|
case script
|
55
59
|
when Script
|
56
60
|
@analyzer.scripts << script
|
@@ -2,23 +2,36 @@ module Querly
|
|
2
2
|
class ScriptEnumerator
|
3
3
|
attr_reader :paths
|
4
4
|
attr_reader :config
|
5
|
+
attr_reader :threads
|
5
6
|
|
6
|
-
def initialize(paths:, config:)
|
7
|
+
def initialize(paths:, config:, threads:)
|
7
8
|
@paths = paths
|
8
9
|
@config = config
|
10
|
+
@threads = threads
|
9
11
|
end
|
10
12
|
|
13
|
+
# Yields `Script` object concurrently, in different threads.
|
11
14
|
def each(&block)
|
15
|
+
if block_given?
|
16
|
+
Parallel.each(each_path, in_threads: threads) do |path|
|
17
|
+
load_script_from_path path, &block
|
18
|
+
end
|
19
|
+
else
|
20
|
+
self.enum_for :each
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def each_path(&block)
|
12
25
|
if block_given?
|
13
26
|
paths.each do |path|
|
14
27
|
if path.directory?
|
15
28
|
enumerate_files_in_dir(path, &block)
|
16
29
|
else
|
17
|
-
|
30
|
+
yield path
|
18
31
|
end
|
19
32
|
end
|
20
33
|
else
|
21
|
-
|
34
|
+
enum_for :each_path
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
@@ -89,7 +102,7 @@ module Querly
|
|
89
102
|
preprocessors.key?(path.extname)
|
90
103
|
end
|
91
104
|
|
92
|
-
|
105
|
+
yield path if should_load_file
|
93
106
|
end
|
94
107
|
end
|
95
108
|
end
|
data/lib/querly/version.rb
CHANGED
data/querly.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: querly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -184,6 +184,20 @@ dependencies:
|
|
184
184
|
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '5.0'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: parallel
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - "~>"
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '1.17'
|
194
|
+
type: :runtime
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - "~>"
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '1.17'
|
187
201
|
description: Querly is a query language and tool to find out method calls from Ruby
|
188
202
|
programs. Define rules to check your program with patterns to find out *bad* pieces.
|
189
203
|
Querly finds out matching pieces from your program.
|