dev_scripts 0.1.6 → 0.1.7
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 +5 -5
- data/Gemfile.lock +5 -1
- data/dev_scripts.gemspec +1 -0
- data/lib/dev_scripts/scripts/expand_block.rb +2 -2
- data/lib/dev_scripts/support/block.rb +54 -0
- data/lib/dev_scripts/support/expanded_block.rb +26 -0
- data/lib/dev_scripts/support/method_call.rb +58 -0
- data/lib/dev_scripts/version.rb +1 -1
- metadata +20 -3
- data/lib/dev_scripts/support/block_expander.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb8b845e411220940dea6320c29b837dc3fe4be0
|
4
|
+
data.tar.gz: f2bb862cda6a06d556077c16ca95737706d8656d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d30b227df38ceb469e5a68a2bab68b55274be68265b2d63f92ae6ca767a3beb4c1a01e88d1eb7e27b4664531c67549c7012f5ea67e6d7afcd79f50a44b57603
|
7
|
+
data.tar.gz: c142dcbf20b61b2e02207180dda4f535ec0181a30be1cadf927dfb2ec442a83a98c2640433d48198972c43728260c419f924d9adcf92b7b7e265b313626bef68
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dev_scripts (0.1.
|
4
|
+
dev_scripts (0.1.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -12,6 +12,7 @@ GEM
|
|
12
12
|
minitest (~> 5.1)
|
13
13
|
tzinfo (~> 1.1)
|
14
14
|
zeitwerk (~> 2.2)
|
15
|
+
ast (2.4.0)
|
15
16
|
byebug (11.0.1)
|
16
17
|
coderay (1.1.2)
|
17
18
|
concurrent-ruby (1.1.5)
|
@@ -44,6 +45,8 @@ GEM
|
|
44
45
|
notiffany (0.1.3)
|
45
46
|
nenv (~> 0.1)
|
46
47
|
shellany (~> 0.0)
|
48
|
+
parser (2.6.5.0)
|
49
|
+
ast (~> 2.4.0)
|
47
50
|
pry (0.12.2)
|
48
51
|
coderay (~> 1.1.0)
|
49
52
|
method_source (~> 0.9.0)
|
@@ -83,6 +86,7 @@ DEPENDENCIES
|
|
83
86
|
dev_scripts!
|
84
87
|
guard
|
85
88
|
guard-rspec
|
89
|
+
parser
|
86
90
|
pry
|
87
91
|
pry-byebug
|
88
92
|
rake (~> 10.0)
|
data/dev_scripts.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'dev_scripts/script'
|
2
|
-
require 'dev_scripts/support/
|
2
|
+
require 'dev_scripts/support/expanded_block'
|
3
3
|
|
4
4
|
DevScripts::Script.define_script :expand_block do
|
5
5
|
args :file_path, :line_number
|
@@ -9,7 +9,7 @@ DevScripts::Script.define_script :expand_block do
|
|
9
9
|
|
10
10
|
File.foreach(file_path).with_index do |file_line, index|
|
11
11
|
if index + 1 == line_number.to_i
|
12
|
-
lines << DevScripts::Support::
|
12
|
+
lines << DevScripts::Support::ExpandedBlock.new(line: file_line)
|
13
13
|
else
|
14
14
|
lines << file_line
|
15
15
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module DevScripts
|
2
|
+
module Support
|
3
|
+
class Block < String
|
4
|
+
def initialize(args_node, block_node)
|
5
|
+
@block_node = block_node
|
6
|
+
|
7
|
+
self << 'do'
|
8
|
+
|
9
|
+
if args_node.children.size > 0
|
10
|
+
self << args_node.children.each_with_object(' |').with_index do |(arg, string), index|
|
11
|
+
string << arg.children.first.to_s
|
12
|
+
|
13
|
+
string << ', ' if index < args_node.children.size - 1
|
14
|
+
string << '|' if index == args_node.children.size - 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
self << "\n"
|
19
|
+
self << ' ' + body
|
20
|
+
self << "\n"
|
21
|
+
self << 'end'
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :block_node
|
27
|
+
|
28
|
+
def args(node)
|
29
|
+
node.children.each_with_object(' |').with_index do |(arg, string), index|
|
30
|
+
string << arg.children.first.to_s
|
31
|
+
|
32
|
+
string << ', ' if index < node.children.size - 1
|
33
|
+
string << "|" if index == node.children.size - 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def block_node_method_call?
|
38
|
+
block_node.type == :send
|
39
|
+
end
|
40
|
+
|
41
|
+
def body
|
42
|
+
if block_node_method_call?
|
43
|
+
MethodCall.new(block_node)
|
44
|
+
else
|
45
|
+
if Symbol === block_node.children.first
|
46
|
+
":#{block_node.children.first}"
|
47
|
+
else
|
48
|
+
block_node.children.first.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'parser/current'
|
2
|
+
require 'dev_scripts/support/block'
|
3
|
+
require 'dev_scripts/support/method_call'
|
4
|
+
|
5
|
+
module DevScripts
|
6
|
+
module Support
|
7
|
+
class ExpandedBlock < String
|
8
|
+
def initialize(line:)
|
9
|
+
parsed = Parser::CurrentRuby.parse(line).children
|
10
|
+
spacing = line.match(/\A\s*/)[0]
|
11
|
+
end_spacing = line.match(/\s*\z/)[0]
|
12
|
+
block_string = DevScripts::Support::Block.new(parsed[1], parsed[2])
|
13
|
+
block_lines = block_string.split("\n")
|
14
|
+
|
15
|
+
self << spacing + DevScripts::Support::MethodCall.new(parsed[0])
|
16
|
+
self << ' '
|
17
|
+
self << block_lines[0]
|
18
|
+
self << "\n"
|
19
|
+
self << spacing + block_lines[1]
|
20
|
+
self << "\n"
|
21
|
+
self << spacing + block_lines[2]
|
22
|
+
self << end_spacing
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module DevScripts
|
2
|
+
module Support
|
3
|
+
class MethodCall < String
|
4
|
+
attr_reader :receiver, :invocation, :args
|
5
|
+
|
6
|
+
def initialize(ast_node)
|
7
|
+
current_receiver, @invocation, *@args = ast_node.children
|
8
|
+
|
9
|
+
invocation_stack = [invocation_with_args]
|
10
|
+
|
11
|
+
while Parser::AST::Node === current_receiver
|
12
|
+
invocation_stack.unshift MethodCall.new(current_receiver).invocation_with_args
|
13
|
+
|
14
|
+
current_receiver, invocation, *args = current_receiver&.children || []
|
15
|
+
end
|
16
|
+
|
17
|
+
invocation_stack.each_with_index do |invocation_string, index|
|
18
|
+
self << '.' if index > 0
|
19
|
+
self << invocation_string.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def invocation_with_args
|
24
|
+
if args && args.size > 0
|
25
|
+
args.each_with_object("#{invocation}(").with_index do |(arg, string), index|
|
26
|
+
string << arg_string(arg)
|
27
|
+
|
28
|
+
string << ', ' if index < args.size - 1
|
29
|
+
string << ')' if index == args.size - 1
|
30
|
+
end
|
31
|
+
else
|
32
|
+
invocation
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def arg_string(arg)
|
37
|
+
case arg.type
|
38
|
+
when :sym
|
39
|
+
":#{arg.children[0]}"
|
40
|
+
when :str
|
41
|
+
"#{arg.children[0]}"
|
42
|
+
when :int
|
43
|
+
"#{arg.children[0].to_i}"
|
44
|
+
when :lvar
|
45
|
+
"#{arg.children[0]}"
|
46
|
+
when :send
|
47
|
+
"#{arg.children[1]}"
|
48
|
+
when :hash
|
49
|
+
arg_string(arg.children[0])
|
50
|
+
when :pair
|
51
|
+
key, value = arg.children
|
52
|
+
|
53
|
+
"#{key.children.first}: #{value.children.last}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/dev_scripts/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Quinones
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: parser
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Register and run scripts for ruby and rails development, with some defaults.
|
126
140
|
email:
|
127
141
|
- cquinones100@gmail.com
|
@@ -148,7 +162,9 @@ files:
|
|
148
162
|
- lib/dev_scripts/scripts/expand_block.rb
|
149
163
|
- lib/dev_scripts/scripts/open_spec_file.rb
|
150
164
|
- lib/dev_scripts/scripts/rubocop_metrics_method_length.rb
|
151
|
-
- lib/dev_scripts/support/
|
165
|
+
- lib/dev_scripts/support/block.rb
|
166
|
+
- lib/dev_scripts/support/expanded_block.rb
|
167
|
+
- lib/dev_scripts/support/method_call.rb
|
152
168
|
- lib/dev_scripts/version.rb
|
153
169
|
homepage:
|
154
170
|
licenses: []
|
@@ -168,7 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
184
|
- !ruby/object:Gem::Version
|
169
185
|
version: '0'
|
170
186
|
requirements: []
|
171
|
-
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.5.2.3
|
172
189
|
signing_key:
|
173
190
|
specification_version: 4
|
174
191
|
summary: Register and run scripts for ruby and rails development
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module DevScripts
|
2
|
-
module Support
|
3
|
-
class BlockExpander
|
4
|
-
|
5
|
-
def initialize(line:)
|
6
|
-
@line = line
|
7
|
-
@body = line.match(/\{.*}\s*\n*\z/)&.send(:[], 0)
|
8
|
-
@spacing = line.match(/\A\s*/)&.send(:[], 0)
|
9
|
-
@argument = line.match(/\|\w+(,\w+)*\|/)&.send(:[], 0)
|
10
|
-
end
|
11
|
-
|
12
|
-
def run
|
13
|
-
line_one + line_two + line_three
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :method_call, :body, :spacing, :argument, :line
|
19
|
-
|
20
|
-
def method_call
|
21
|
-
line.split('').each_with_object('') do |character, new_line|
|
22
|
-
return new_line if character == '{'
|
23
|
-
|
24
|
-
new_line << character
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def new_body
|
29
|
-
body
|
30
|
-
.gsub('{', 'do')
|
31
|
-
.gsub(/\|\w+(,\w+)*\|/) { |match| "#{match}\n#{spacing}" }
|
32
|
-
.gsub('}', )
|
33
|
-
end
|
34
|
-
|
35
|
-
def line_one
|
36
|
-
method_call.gsub(/\s*\z/, '') + " do#{argument ? ' ' + argument : ''}\n"
|
37
|
-
end
|
38
|
-
|
39
|
-
def line_two
|
40
|
-
spacing +
|
41
|
-
' ' +
|
42
|
-
body.gsub(/\A{\s*(\|\w+(,\w+)*\|)*\s*/, '').gsub(/\s*}\s*\z/, '') +
|
43
|
-
"\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
def line_three
|
47
|
-
spacing + body.match(/}\s*/)[0].gsub('}', 'end')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|