ffast 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +104 -1
- data/.sourcelevel.yml +2 -0
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/docs/videos.md +5 -1
- data/fast.gemspec +3 -2
- data/lib/fast.rb +78 -10
- data/lib/fast/cli.rb +26 -7
- data/lib/fast/experiment.rb +1 -2
- data/lib/fast/git.rb +101 -0
- data/lib/fast/shortcut.rb +6 -9
- data/lib/fast/version.rb +1 -1
- metadata +29 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3942d57d80b4c4a1cd1c8ff40f18cc56508a51f4b6cae53480536f7c36a60b05
|
4
|
+
data.tar.gz: b60976ea570cf722ae6face8541881c6a1231b2d645727f25231a05c9f33f7ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4df11570f2b2cc164dbd43815a37443541c98c955d6c84ea0b24564fd03b8534cf73479844393ecd72c794231ad40baf678784f9863a8f90c157ac8477f3c9d
|
7
|
+
data.tar.gz: d9481952776fc77d251a3c9f518f41e20d672298e9ff01b53b8673a0c0bc38f4919e4dd7234365e8044f5cef8e0738823d847900bea790f9796e6d8554342a06
|
data/.rubocop.yml
CHANGED
@@ -8,11 +8,114 @@ AllCops:
|
|
8
8
|
Exclude:
|
9
9
|
- 'tmp/**/*'
|
10
10
|
- 'examples/*'
|
11
|
-
TargetRubyVersion: 2.
|
11
|
+
TargetRubyVersion: 2.6
|
12
12
|
|
13
13
|
Layout/LineLength:
|
14
14
|
Enabled: false
|
15
15
|
|
16
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceAroundMethodCallOperator:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Lint/DuplicateElsifCondition:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Lint/DuplicateRescueException:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Lint/EmptyConditionalBody:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Lint/FloatComparison:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Lint/MissingSuper:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Lint/OutOfRangeRegexpRef:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Lint/SelfAssignment:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Lint/TopLevelReturnWithArgument:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Lint/UnreachableLoop:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
|
53
|
+
Lint/DeprecatedOpenSSLConstant:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Lint/MixedRegexpCaptureTypes:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Lint/RaiseException:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Lint/StructNewOverride:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/AccessorGrouping:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/ArrayCoercion:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/BisectedAttrAccessor:
|
72
|
+
Enabled: true
|
73
|
+
|
74
|
+
Style/CaseLikeIf:
|
75
|
+
Enabled: true
|
76
|
+
|
77
|
+
Style/ExplicitBlockArgument:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Style/ExponentialNotation:
|
81
|
+
Enabled: true
|
82
|
+
|
83
|
+
Style/GlobalStdStream:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/HashAsLastArrayItem:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/HashLikeCase:
|
90
|
+
Enabled: true
|
91
|
+
|
92
|
+
Style/OptionalBooleanParameter:
|
93
|
+
Enabled: true
|
94
|
+
|
95
|
+
Style/RedundantAssignment:
|
96
|
+
Enabled: true
|
97
|
+
|
98
|
+
Style/RedundantFetchBlock:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
Style/RedundantFileExtensionInRequire:
|
102
|
+
Enabled: true
|
103
|
+
|
104
|
+
Style/SingleArgumentDig:
|
105
|
+
Enabled: true
|
106
|
+
|
107
|
+
Style/StringConcatenation:
|
108
|
+
Enabled: true
|
109
|
+
|
110
|
+
Style/RedundantRegexpCharacterClass:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
Style/RedundantRegexpEscape:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
Style/SlicingWithRange:
|
117
|
+
Enabled: true
|
118
|
+
|
16
119
|
Metrics/BlockLength:
|
17
120
|
Exclude:
|
18
121
|
- 'spec/**/*'
|
data/.sourcelevel.yml
ADDED
data/.travis.yml
CHANGED
@@ -6,7 +6,7 @@ env:
|
|
6
6
|
rvm:
|
7
7
|
- 2.6.3
|
8
8
|
before_install:
|
9
|
-
gem install bundler -v 1.
|
9
|
+
gem install bundler -v 2.1.4
|
10
10
|
before_script:
|
11
11
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
12
12
|
- chmod +x ./cc-test-reporter
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ The current version of Fast covers the following token elements:
|
|
32
32
|
to build custom rules.
|
33
33
|
- `.<method-name>` - will call `<method-name>` from the `node`
|
34
34
|
|
35
|
-
The syntax is inspired by the [RuboCop Node Pattern](https://github.com/
|
35
|
+
The syntax is inspired by the [RuboCop Node Pattern](https://github.com/rubocop-hq/rubocop-ast/blob/master/lib/rubocop/ast/node_pattern.rb).
|
36
36
|
|
37
37
|
## Installation
|
38
38
|
|
data/docs/videos.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Videos
|
2
2
|
|
3
|
-
- Grepping Ruby code like a boss
|
3
|
+
- [Ruby Kaigi TakeOut 2020: Grepping Ruby code like a boss](https://www.youtube.com/watch?v=YzcYXB4L2so&feature=youtu.be&t=11855)
|
4
|
+
|
5
|
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/YzcYXB4L2so?start=11855" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
6
|
+
|
7
|
+
Also, similar livecoding session at [RubyConf Brazil 2019 (Portuguese)](https://www.eventials.com/locaweb/jonatas-paganini-live-coding-grepping-ruby-code-like-a-boss/#_=_).
|
4
8
|
|
5
9
|
- Introduction to [inline code](https://www.youtube.com/watch?v=KQXglNLUv7o).
|
6
10
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/KQXglNLUv7o" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
data/fast.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'fast/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'ffast'
|
9
9
|
spec.version = Fast::VERSION
|
10
|
-
spec.required_ruby_version = '>= 2.
|
10
|
+
spec.required_ruby_version = '>= 2.6'
|
11
11
|
spec.authors = ['Jônatas Davi Paganini']
|
12
12
|
spec.email = ['jonatasdp@gmail.com']
|
13
13
|
spec.homepage = 'https://jonatas.github.io/fast/'
|
@@ -34,11 +34,12 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'guard-livereload'
|
35
35
|
spec.add_development_dependency 'guard-rspec'
|
36
36
|
spec.add_development_dependency 'pry'
|
37
|
+
spec.add_development_dependency 'git'
|
37
38
|
spec.add_development_dependency 'rake'
|
38
39
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
40
|
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
40
41
|
spec.add_development_dependency 'rubocop'
|
41
42
|
spec.add_development_dependency 'rubocop-performance'
|
42
43
|
spec.add_development_dependency 'rubocop-rspec'
|
43
|
-
spec.add_development_dependency 'simplecov'
|
44
|
+
spec.add_development_dependency 'simplecov', '~> 0.10', '< 0.18'
|
44
45
|
end
|
data/lib/fast.rb
CHANGED
@@ -67,18 +67,86 @@ module Fast
|
|
67
67
|
%\d # bind extra arguments to the expression
|
68
68
|
/x.freeze
|
69
69
|
|
70
|
+
# Set some convention methods from file.
|
71
|
+
class Node < Astrolabe::Node
|
72
|
+
# @return [String] with path of the file or simply buffer name.
|
73
|
+
def buffer_name
|
74
|
+
expression.source_buffer.name
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Parser::Source::Range] from the expression
|
78
|
+
def expression
|
79
|
+
location.expression
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [String] with the content of the #expression
|
83
|
+
def source
|
84
|
+
expression.source
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [Boolean] true if a file exists with the #buffer_name
|
88
|
+
def from_file?
|
89
|
+
File.exist?(buffer_name)
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [Array<String>] with authors from the current expression range
|
93
|
+
def blame_authors
|
94
|
+
`git blame -L #{expression.first_line},#{expression.last_line} #{buffer_name}`.lines.map do |line|
|
95
|
+
line.split('(')[1].split(/\d+/).first.strip
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [String] with the first element from #blame_authors
|
100
|
+
def author
|
101
|
+
blame_authors.first
|
102
|
+
end
|
103
|
+
|
104
|
+
# Search recursively into a node and its children using a pattern.
|
105
|
+
# @param [String] pattern
|
106
|
+
# @param [Array] *args extra arguments to interpolate in the pattern.
|
107
|
+
# @return [Array<Fast::Node>>] with files and results
|
108
|
+
def search(pattern, *args)
|
109
|
+
Fast.search(pattern, self, *args)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Captures elements from search recursively
|
113
|
+
# @param [String] pattern
|
114
|
+
# @param [Array] *args extra arguments to interpolate in the pattern.
|
115
|
+
# @return [Array<Fast::Node>>] with files and results
|
116
|
+
def capture(pattern, *args)
|
117
|
+
Fast.capture(pattern, self, *args)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Custom builder allow us to set a buffer name for each Node
|
122
|
+
class Builder < Astrolabe::Builder
|
123
|
+
attr_writer :buffer_name
|
124
|
+
# Generates {Node} from the given information.
|
125
|
+
#
|
126
|
+
# @return [Node] the generated node
|
127
|
+
def n(type, children, source_map)
|
128
|
+
Node.new(type, children, location: source_map, buffer_name: @buffer_name)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
70
132
|
class << self
|
71
|
-
# @return [
|
133
|
+
# @return [Fast::Node] from the parsed content
|
72
134
|
# @example
|
73
135
|
# Fast.ast("1") # => s(:int, 1)
|
74
136
|
# Fast.ast("a.b") # => s(:send, s(:send, nil, :a), :b)
|
75
137
|
def ast(content, buffer_name: '(string)')
|
76
138
|
buffer = Parser::Source::Buffer.new(buffer_name)
|
77
139
|
buffer.source = content
|
78
|
-
Parser::CurrentRuby.new(
|
140
|
+
Parser::CurrentRuby.new(builder_for(buffer_name)).parse(buffer)
|
141
|
+
end
|
142
|
+
|
143
|
+
def builder_for(buffer_name)
|
144
|
+
builder = Builder.new
|
145
|
+
builder.buffer_name = buffer_name
|
146
|
+
builder
|
79
147
|
end
|
80
148
|
|
81
|
-
# @return [
|
149
|
+
# @return [Fast::Node] parsed from file content
|
82
150
|
# caches the content based on the filename.
|
83
151
|
# @example
|
84
152
|
# Fast.ast_from_file("example.rb") # => s(...)
|
@@ -96,7 +164,7 @@ module Fast
|
|
96
164
|
end
|
97
165
|
|
98
166
|
# Search with pattern directly on file
|
99
|
-
# @return [Array<
|
167
|
+
# @return [Array<Fast::Node>] that matches the pattern
|
100
168
|
def search_file(pattern, file)
|
101
169
|
node = ast_from_file(file)
|
102
170
|
return [] unless node
|
@@ -107,7 +175,7 @@ module Fast
|
|
107
175
|
# Search with pattern on a directory or multiple files
|
108
176
|
# @param [String] pattern
|
109
177
|
# @param [Array<String>] *locations where to search. Default is '.'
|
110
|
-
# @return [Hash<String,Array<
|
178
|
+
# @return [Hash<String,Array<Fast::Node>>] with files and results
|
111
179
|
def search_all(pattern, locations = ['.'], parallel: true, on_result: nil)
|
112
180
|
group_results(build_grouped_search(:search_file, pattern, on_result),
|
113
181
|
locations, parallel: parallel)
|
@@ -241,7 +309,7 @@ module Fast
|
|
241
309
|
# Useful to index abstract patterns or similar code structure.
|
242
310
|
# @see https://jonatas.github.io/fast/similarity_tutorial/
|
243
311
|
# @return [String] with an pattern to search from it.
|
244
|
-
# @param node [
|
312
|
+
# @param node [Fast::Node]
|
245
313
|
# @example
|
246
314
|
# Fast.expression_from(Fast.ast('1')) # => '(int _)'
|
247
315
|
# Fast.expression_from(Fast.ast('a = 1')) # => '(lvasgn _ (int _))'
|
@@ -250,7 +318,7 @@ module Fast
|
|
250
318
|
case node
|
251
319
|
when Parser::AST::Node
|
252
320
|
children_expression = node.children.map(&method(:expression_from)).join(' ')
|
253
|
-
"(#{node.type}#{
|
321
|
+
"(#{node.type}#{" #{children_expression}" if node.children.any?})"
|
254
322
|
when nil, 'nil'
|
255
323
|
'nil'
|
256
324
|
when Symbol, String, Numeric
|
@@ -305,14 +373,14 @@ module Fast
|
|
305
373
|
when '{' then Any.new(parse_until_peek('}'))
|
306
374
|
when '[' then All.new(parse_until_peek(']'))
|
307
375
|
when /^"/ then FindString.new(token[1..-2])
|
308
|
-
when /^#\w/ then MethodCall.new(token[1
|
309
|
-
when /^\.\w[\w\d_]+\?/ then InstanceMethodCall.new(token[1
|
376
|
+
when /^#\w/ then MethodCall.new(token[1..])
|
377
|
+
when /^\.\w[\w\d_]+\?/ then InstanceMethodCall.new(token[1..])
|
310
378
|
when '$' then Capture.new(parse)
|
311
379
|
when '!' then (@tokens.any? ? Not.new(parse) : Find.new(token))
|
312
380
|
when '?' then Maybe.new(parse)
|
313
381
|
when '^' then Parent.new(parse)
|
314
382
|
when '\\' then FindWithCapture.new(parse)
|
315
|
-
when /^%\d/ then FindFromArgument.new(token[1
|
383
|
+
when /^%\d/ then FindFromArgument.new(token[1..])
|
316
384
|
else Find.new(token)
|
317
385
|
end
|
318
386
|
end
|
data/lib/fast/cli.rb
CHANGED
@@ -36,12 +36,16 @@ module Fast
|
|
36
36
|
# @param headless [Boolean] Skip printing the file name and line before content
|
37
37
|
# @example
|
38
38
|
# Fast.highlight(Fast.search(...))
|
39
|
-
def report(result, show_sexp: false, file: nil, headless: false, colorize: true)
|
39
|
+
def report(result, show_link: false, show_sexp: false, file: nil, headless: false, bodyless: false, colorize: true) # rubocop:disable Metrics/ParameterLists
|
40
40
|
if file
|
41
41
|
line = result.loc.expression.line if result.is_a?(Parser::AST::Node)
|
42
|
-
|
42
|
+
if show_link
|
43
|
+
puts(result.link)
|
44
|
+
elsif !headless
|
45
|
+
puts(highlight("# #{file}:#{line}", colorize: colorize))
|
46
|
+
end
|
43
47
|
end
|
44
|
-
puts
|
48
|
+
puts(highlight(result, show_sexp: show_sexp, colorize: colorize)) unless bodyless
|
45
49
|
end
|
46
50
|
|
47
51
|
# Command Line Interface for Fast
|
@@ -69,6 +73,11 @@ module Fast
|
|
69
73
|
@show_sexp = true
|
70
74
|
end
|
71
75
|
|
76
|
+
opts.on('--link', 'Print link to repository URL instead of code') do
|
77
|
+
require 'fast/git'
|
78
|
+
@show_link = true
|
79
|
+
end
|
80
|
+
|
72
81
|
opts.on('-p', '--parallel', 'Paralelize search') do
|
73
82
|
@parallel = true
|
74
83
|
end
|
@@ -81,6 +90,10 @@ module Fast
|
|
81
90
|
@headless = true
|
82
91
|
end
|
83
92
|
|
93
|
+
opts.on('--bodyless', 'Print results without the code details') do
|
94
|
+
@bodyless = true
|
95
|
+
end
|
96
|
+
|
84
97
|
opts.on('--pry', 'Jump into a pry session with results') do
|
85
98
|
@pry = true
|
86
99
|
require 'pry'
|
@@ -116,12 +129,13 @@ module Fast
|
|
116
129
|
end
|
117
130
|
|
118
131
|
def replace_args_with_shortcut(args)
|
119
|
-
shortcut = find_shortcut args.first[1
|
132
|
+
shortcut = find_shortcut args.first[1..]
|
133
|
+
|
120
134
|
if shortcut.single_run_with_block?
|
121
135
|
shortcut.run
|
122
136
|
exit
|
123
137
|
else
|
124
|
-
args.one? ? shortcut.args : shortcut.merge_args(args[1
|
138
|
+
args.one? ? shortcut.args : shortcut.merge_args(args[1..])
|
125
139
|
end
|
126
140
|
end
|
127
141
|
|
@@ -195,7 +209,13 @@ module Fast
|
|
195
209
|
# Report results using the actual options binded from command line.
|
196
210
|
# @see Fast.report
|
197
211
|
def report(file, result)
|
198
|
-
Fast.report(result,
|
212
|
+
Fast.report(result,
|
213
|
+
file: file,
|
214
|
+
show_link: @show_link,
|
215
|
+
show_sexp: @show_sexp,
|
216
|
+
headless: @headless,
|
217
|
+
bodyless: @bodyless,
|
218
|
+
colorize: @colorize)
|
199
219
|
end
|
200
220
|
|
201
221
|
# Find shortcut by name. Preloads all `Fastfiles` before start.
|
@@ -206,7 +226,6 @@ module Fast
|
|
206
226
|
Fast.load_fast_files!
|
207
227
|
|
208
228
|
shortcut = Fast.shortcuts[name] || Fast.shortcuts[name.to_sym]
|
209
|
-
|
210
229
|
shortcut || exit_shortcut_not_found(name)
|
211
230
|
end
|
212
231
|
|
data/lib/fast/experiment.rb
CHANGED
@@ -290,7 +290,7 @@ module Fast
|
|
290
290
|
Fast.search(experiment.expression, @ast) || []
|
291
291
|
end
|
292
292
|
|
293
|
-
# rubocop:disable Metrics/
|
293
|
+
# rubocop:disable Metrics/MethodLength
|
294
294
|
#
|
295
295
|
# Execute partial replacements generating new file with the
|
296
296
|
# content replaced.
|
@@ -312,7 +312,6 @@ module Fast
|
|
312
312
|
new_content
|
313
313
|
end
|
314
314
|
|
315
|
-
# rubocop:enable Metrics/AbcSize
|
316
315
|
# rubocop:enable Metrics/MethodLength
|
317
316
|
|
318
317
|
# Write new file name depending on the combination
|
data/lib/fast/git.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Git plugin for Fast::Node.
|
4
|
+
# It allows to easily access metadata from current file.
|
5
|
+
module Fast
|
6
|
+
# This is not required by default, so to use it, you should require it first.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# require 'fast/git'
|
10
|
+
# Fast.ast_from_file('lib/fast.rb').git_log.first.author.name # => "Jonatas Davi Paganini"
|
11
|
+
class Node < Astrolabe::Node
|
12
|
+
# @return [Git::Base] from current directory
|
13
|
+
def git
|
14
|
+
require 'git' unless defined? Git
|
15
|
+
Git.open('.')
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Git::Object::Blob] from current #buffer_name
|
19
|
+
def git_blob
|
20
|
+
return unless from_file?
|
21
|
+
|
22
|
+
git.gblob(buffer_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Git::Log] from the current #git_blob
|
26
|
+
# buffer-name
|
27
|
+
def git_log
|
28
|
+
git_blob.log
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Git::Object::Commit]
|
32
|
+
def last_commit
|
33
|
+
git_log.first
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String] with last commit SHA
|
37
|
+
def sha
|
38
|
+
last_commit.sha
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String] with remote URL
|
42
|
+
def remote_url
|
43
|
+
git.remote.url
|
44
|
+
end
|
45
|
+
|
46
|
+
# Given #remote_url is "git@github.com:namespace/project.git"
|
47
|
+
# Or #remote_url is "https://github.com/namespace/project.git"
|
48
|
+
# @return [String] "https://github.com/namespace/project"
|
49
|
+
def project_url
|
50
|
+
return remote_url.gsub(/\.git$/, '') if remote_url.start_with?('https')
|
51
|
+
|
52
|
+
remote_url
|
53
|
+
.gsub('git@', 'https://')
|
54
|
+
.gsub(/:(\w)/, '/\\1')
|
55
|
+
.gsub(/\.git$/, '')
|
56
|
+
end
|
57
|
+
|
58
|
+
def file
|
59
|
+
buffer_name.gsub("#{Dir.pwd}/", '')
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return
|
63
|
+
def line_range
|
64
|
+
lines.map { |l| "L#{l}" }.join('-')
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array] with lines range
|
68
|
+
def lines
|
69
|
+
exp = loc.expression
|
70
|
+
first_line = exp.first_line
|
71
|
+
last_line = exp.last_line
|
72
|
+
[first_line, last_line].uniq
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Integer] lines of code from current block
|
76
|
+
def lines_of_code
|
77
|
+
lines.last - lines.first + 1
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String] a markdown link with #md_link_description and #link
|
81
|
+
def md_link(text = md_link_description)
|
82
|
+
"[#{text}](#{link})"
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [String] with the source cutting arguments from method calls to be
|
86
|
+
# able to create a markdown link without parens.
|
87
|
+
def md_link_description
|
88
|
+
source[/([^\r\(]+)\(/, 1] || source
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [String] with formatted repositorym link
|
92
|
+
def link
|
93
|
+
"#{project_url}/blob/master/#{buffer_name}##{line_range}"
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [String] with permanent link to the actual commit
|
97
|
+
def permalink
|
98
|
+
"#{project_url}/blob/#{sha}/#{buffer_name}##{line_range}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/fast/shortcut.rb
CHANGED
@@ -54,19 +54,16 @@ module Fast
|
|
54
54
|
@block && @args.nil?
|
55
55
|
end
|
56
56
|
|
57
|
-
def options
|
58
|
-
@args.select { |arg| arg.start_with? '-' }
|
59
|
-
end
|
60
|
-
|
61
|
-
def params
|
62
|
-
@args - options
|
63
|
-
end
|
64
|
-
|
65
57
|
# Merge extra arguments from input returning a new arguments array keeping
|
66
58
|
# the options from previous alias and replacing the files with the
|
67
59
|
# @param [Array] extra_args
|
68
60
|
def merge_args(extra_args)
|
69
|
-
|
61
|
+
all_args = (@args + extra_args).uniq
|
62
|
+
options = all_args.select { |arg| arg.start_with? '-' }
|
63
|
+
files = extra_args.select(&File.method(:exists?))
|
64
|
+
command = (@args - options - files).first
|
65
|
+
|
66
|
+
[command, *options, *files]
|
70
67
|
end
|
71
68
|
|
72
69
|
# If the shortcut was defined with a single block and no extra arguments, it
|
data/lib/fast/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jônatas Davi Paganini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: astrolabe
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: git
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rake
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,16 +238,22 @@ dependencies:
|
|
224
238
|
name: simplecov
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
226
240
|
requirements:
|
227
|
-
- - "
|
241
|
+
- - "~>"
|
228
242
|
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
243
|
+
version: '0.10'
|
244
|
+
- - "<"
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
version: '0.18'
|
230
247
|
type: :development
|
231
248
|
prerelease: false
|
232
249
|
version_requirements: !ruby/object:Gem::Requirement
|
233
250
|
requirements:
|
234
|
-
- - "
|
251
|
+
- - "~>"
|
235
252
|
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
253
|
+
version: '0.10'
|
254
|
+
- - "<"
|
255
|
+
- !ruby/object:Gem::Version
|
256
|
+
version: '0.18'
|
237
257
|
description: Allow you to search for code using node pattern syntax.
|
238
258
|
email:
|
239
259
|
- jonatasdp@gmail.com
|
@@ -247,6 +267,7 @@ files:
|
|
247
267
|
- ".projections.json"
|
248
268
|
- ".rspec"
|
249
269
|
- ".rubocop.yml"
|
270
|
+
- ".sourcelevel.yml"
|
250
271
|
- ".travis.yml"
|
251
272
|
- CODE_OF_CONDUCT.md
|
252
273
|
- Fastfile
|
@@ -286,6 +307,7 @@ files:
|
|
286
307
|
- lib/fast.rb
|
287
308
|
- lib/fast/cli.rb
|
288
309
|
- lib/fast/experiment.rb
|
310
|
+
- lib/fast/git.rb
|
289
311
|
- lib/fast/rewriter.rb
|
290
312
|
- lib/fast/shortcut.rb
|
291
313
|
- lib/fast/version.rb
|
@@ -303,7 +325,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
303
325
|
requirements:
|
304
326
|
- - ">="
|
305
327
|
- !ruby/object:Gem::Version
|
306
|
-
version: '2.
|
328
|
+
version: '2.6'
|
307
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
308
330
|
requirements:
|
309
331
|
- - ">="
|