node_mutation 1.4.4 → 1.5.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/Gemfile.lock +2 -2
- data/README.md +0 -2
- data/lib/node_mutation/parser_adapter.rb +1 -1
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +0 -16
- data/sig/node_mutation.rbs +0 -2
- metadata +3 -4
- data/lib/node_mutation/action/insert_after_action.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b66c8223045972f4f91cdae0b61a5589c04e7f53f3eedf66b1c0eebee9d66b1c
|
4
|
+
data.tar.gz: 64a47a10bce6886a876cd04b08ff37118e6094bcc40d1e909e861d6f25c37d43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f5cd0bc631511de6d7b250dec14869ce1e19d5c311ac59e5722578f2fa15f51b17be600d5fc59a3ef5ffaa1607e209ccc6e611e2046f1a9005cffb693367a9
|
7
|
+
data.tar.gz: 7d3496c675ed29a8ddaa35d3fbf4b538677a44016696c40020e518afa62526fa5e7ad2abec2b7339732adabb820fa037795c3d8597b0149a2cd0502c23c95883
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_mutation (1.
|
4
|
+
node_mutation (1.5.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
7
|
|
@@ -75,7 +75,7 @@ GEM
|
|
75
75
|
thor (1.2.1)
|
76
76
|
tzinfo (2.0.5)
|
77
77
|
concurrent-ruby (~> 1.0)
|
78
|
-
zeitwerk (2.6.
|
78
|
+
zeitwerk (2.6.1)
|
79
79
|
|
80
80
|
PLATFORMS
|
81
81
|
x86_64-darwin-21
|
data/README.md
CHANGED
@@ -37,8 +37,6 @@ mutation.append node, 'include FactoryGirl::Syntax::Methods'
|
|
37
37
|
mutation.delete node, :dot, :message, and_comma: true
|
38
38
|
# insert code to the ast node.
|
39
39
|
mutation.insert node, 'URI.', at: 'beginning'
|
40
|
-
# insert code next to the ast node.
|
41
|
-
mutation.insert_after node, '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
|
42
40
|
# prepend code to the ast node.
|
43
41
|
mutation.prepend node, '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
|
44
42
|
# remove source code of the ast node
|
@@ -6,7 +6,7 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def rewritten_source(node, code)
|
9
|
-
code.gsub(/{{(
|
9
|
+
code.gsub(/{{(.+?)}}/m) do
|
10
10
|
old_code = Regexp.last_match(1)
|
11
11
|
if node.respond_to?(old_code.split('.').first)
|
12
12
|
evaluated = child_node_by_name(node, old_code)
|
data/lib/node_mutation.rb
CHANGED
@@ -18,7 +18,6 @@ class NodeMutation
|
|
18
18
|
autoload :AppendAction, 'node_mutation/action/append_action'
|
19
19
|
autoload :DeleteAction, 'node_mutation/action/delete_action'
|
20
20
|
autoload :InsertAction, 'node_mutation/action/insert_action'
|
21
|
-
autoload :InsertAfterAction, 'node_mutation/action/insert_after_action'
|
22
21
|
autoload :RemoveAction, 'node_mutation/action/remove_action'
|
23
22
|
autoload :PrependAction, 'node_mutation/action/prepend_action'
|
24
23
|
autoload :ReplaceAction, 'node_mutation/action/replace_action'
|
@@ -112,21 +111,6 @@ class NodeMutation
|
|
112
111
|
@actions << InsertAction.new(node, code, at: at, to: to).process
|
113
112
|
end
|
114
113
|
|
115
|
-
# Insert code next to the ast node.
|
116
|
-
# @param node [Node] ast node
|
117
|
-
# @param code [String] new code to insert.
|
118
|
-
# @example
|
119
|
-
# source code of the ast node is
|
120
|
-
# Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
|
121
|
-
# then we call
|
122
|
-
# mutation.insert_after(node, "{{receiver}}.secret_key_base = \"#{SecureRandom.hex(64)}\"")
|
123
|
-
# the source code will be rewritten to
|
124
|
-
# Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
|
125
|
-
# Synvert::Application.config.secret_key_base = "bf4f3f46924ecd9adcb6515681c78144545bba454420973a274d7021ff946b8ef043a95ca1a15a9d1b75f9fbdf85d1a3afaf22f4e3c2f3f78e24a0a188b581df"
|
126
|
-
def insert_after(node, code)
|
127
|
-
@actions << InsertAfterAction.new(node, code).process
|
128
|
-
end
|
129
|
-
|
130
114
|
# Prepend code to the ast node.
|
131
115
|
# @param node [Node] ast node
|
132
116
|
# @param code [String] new code to prepend.
|
data/sig/node_mutation.rbs
CHANGED
@@ -27,8 +27,6 @@ module NodeMutation[T]
|
|
27
27
|
|
28
28
|
def insert: (node: T, code: String, ?at: "beginning" | "end", ?to: nil | String) -> void
|
29
29
|
|
30
|
-
def insert_after: (node: T, code: String) -> void
|
31
|
-
|
32
30
|
def prepend: (node: T, code: String) -> void
|
33
31
|
|
34
32
|
def remove: (node: T, **options: { and_comma: bool }) -> void
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: node_mutation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,7 +58,6 @@ files:
|
|
58
58
|
- lib/node_mutation/action/append_action.rb
|
59
59
|
- lib/node_mutation/action/delete_action.rb
|
60
60
|
- lib/node_mutation/action/insert_action.rb
|
61
|
-
- lib/node_mutation/action/insert_after_action.rb
|
62
61
|
- lib/node_mutation/action/noop_action.rb
|
63
62
|
- lib/node_mutation/action/prepend_action.rb
|
64
63
|
- lib/node_mutation/action/remove_action.rb
|
@@ -96,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
95
|
- !ruby/object:Gem::Version
|
97
96
|
version: '0'
|
98
97
|
requirements: []
|
99
|
-
rubygems_version: 3.3.
|
98
|
+
rubygems_version: 3.3.22
|
100
99
|
signing_key:
|
101
100
|
specification_version: 4
|
102
101
|
summary: ast node mutation apis
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# InsertAfterAction to insert code next to the node.
|
4
|
-
class NodeMutation::InsertAfterAction < NodeMutation::Action
|
5
|
-
private
|
6
|
-
|
7
|
-
# Calculate the begin and end positions.
|
8
|
-
def calculate_position
|
9
|
-
@start = NodeMutation.adapter.get_end(@node)
|
10
|
-
@end = @start
|
11
|
-
end
|
12
|
-
|
13
|
-
# Indent of the node.
|
14
|
-
#
|
15
|
-
# @param node [Parser::AST::Node]
|
16
|
-
# @return [Integer] indent size
|
17
|
-
def indent(node)
|
18
|
-
' ' * NodeMutation.adapter.get_start_loc(node).column
|
19
|
-
end
|
20
|
-
end
|