dev_scripts 0.1.5 → 0.1.6
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/.vscode/tasks.json +6 -0
- data/lib/dev_scripts.rb +1 -0
- data/lib/dev_scripts/scripts/expand_block.rb +20 -0
- data/lib/dev_scripts/support/block_expander.rb +51 -0
- data/lib/dev_scripts/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d228641ef9316118dc6db77ce51b8e427dce277873ba1698ef02462ba5c9b18d
|
4
|
+
data.tar.gz: 97d738e8c9632d42a66944a2c7fcc9cefaa3f4cea46da91e497b8df18d30f1c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d81e8075cb5d3637d754e3d377fbb6bfb37499644390eb5acaee3eef424f4c68cb1bbf29582647543e19d7c610c08df59637a5cc34ae61a7c24064b8cad44f
|
7
|
+
data.tar.gz: 2cb25859255da05f5f1f25d176c57c6a9cb8686a596ad30ffde2243537e0985b4aefe6f0193eeb33fed7dfd6df236f12a32877c0604b71d582c7d8c06cd2f2c2
|
data/.vscode/tasks.json
CHANGED
@@ -6,6 +6,12 @@
|
|
6
6
|
"type": "shell",
|
7
7
|
"command": "dev_scripts open_spec_file ${relativeFile}",
|
8
8
|
"problemMatcher": []
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"label": "expand block",
|
12
|
+
"type": "shell",
|
13
|
+
"command": "dev_scripts expand_block ${relativeFile} ${lineNumber}",
|
14
|
+
"problemMatcher": []
|
9
15
|
}
|
10
16
|
]
|
11
17
|
}
|
data/lib/dev_scripts.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'dev_scripts/script'
|
2
|
+
require 'dev_scripts/support/block_expander'
|
3
|
+
|
4
|
+
DevScripts::Script.define_script :expand_block do
|
5
|
+
args :file_path, :line_number
|
6
|
+
|
7
|
+
execute do
|
8
|
+
lines = []
|
9
|
+
|
10
|
+
File.foreach(file_path).with_index do |file_line, index|
|
11
|
+
if index + 1 == line_number.to_i
|
12
|
+
lines << DevScripts::Support::BlockExpander.new(line: file_line).run
|
13
|
+
else
|
14
|
+
lines << file_line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
File.open(file_path, 'w') { |file| file.write(lines.join('')) }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
data/lib/dev_scripts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Quinones
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,8 +145,10 @@ files:
|
|
145
145
|
- exe/dev_scripts
|
146
146
|
- lib/dev_scripts.rb
|
147
147
|
- lib/dev_scripts/script.rb
|
148
|
+
- lib/dev_scripts/scripts/expand_block.rb
|
148
149
|
- lib/dev_scripts/scripts/open_spec_file.rb
|
149
150
|
- lib/dev_scripts/scripts/rubocop_metrics_method_length.rb
|
151
|
+
- lib/dev_scripts/support/block_expander.rb
|
150
152
|
- lib/dev_scripts/version.rb
|
151
153
|
homepage:
|
152
154
|
licenses: []
|
@@ -166,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
168
|
- !ruby/object:Gem::Version
|
167
169
|
version: '0'
|
168
170
|
requirements: []
|
169
|
-
|
170
|
-
rubygems_version: 2.5.2.3
|
171
|
+
rubygems_version: 3.0.3
|
171
172
|
signing_key:
|
172
173
|
specification_version: 4
|
173
174
|
summary: Register and run scripts for ruby and rails development
|