node_mutation 1.4.4 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e22702ce72aa488794a76e0d762283155783d56e1af0e5135ad91d768a917ab
4
- data.tar.gz: 4b0c210a8c94cc46bfce28570164210cc2f54bb768df1b470ea3c27e8f2a7c98
3
+ metadata.gz: 44339bec6d4624f5f7cf60b9253e701c7215f2b5bae0094b0532bf86e4c6cf91
4
+ data.tar.gz: 4878c3c9f61830b728d6ea21424588d62c039e42aa5a029b1786844a1c7b74db
5
5
  SHA512:
6
- metadata.gz: 22d09f324deb8982994201df87bfcf21562576def43034ac9a5f0a0599ee264df8852a0cde609dc41098d314b9fed7ec70e135a51c0ffe8c9ffa293f2436820c
7
- data.tar.gz: a0348978965f9e3fdbdfe20bba6ad40830f1b1f039859f2fafecaa4329f4f81d52cee64f5bcbaf69c32229b75126cb9554c55256fb421134073d19de2759c2bb
6
+ metadata.gz: 1d0b12e168a2a8aa7a8019484125bd0edcdb159846216de1d1822e1a75f1b47e1f57f87b5de0cb94a0ebec45e950b2f32c9349c76294ac6156d0d382be85d52e
7
+ data.tar.gz: deb03d485ddf7ca91797cafbe28526ea5e91b7f862c71173e801587d727ced13680f7ff4dc3d4f2d563e8830c52622e5ce44dc4f02d84ddc6f26f572941db6d5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.5.1 (2022-10-19)
4
+
5
+ * Better error message for unknown code
6
+
7
+ ## 1.5.0 (2022-10-17)
8
+
9
+ * Remove `insert_after`
10
+ * Fix regexp to match evaluated value
11
+
3
12
  ## 1.4.4 (2022-09-26)
4
13
 
5
14
  * Parser adapter `child_node_by_name` support function call
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.4.4)
4
+ node_mutation (1.5.1)
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.0)
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,9 +6,9 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
6
6
  end
7
7
 
8
8
  def rewritten_source(node, code)
9
- code.gsub(/{{(.*?)}}/m) do
9
+ code.gsub(/{{(.+?)}}/m) do
10
10
  old_code = Regexp.last_match(1)
11
- if node.respond_to?(old_code.split('.').first)
11
+ begin
12
12
  evaluated = child_node_by_name(node, old_code)
13
13
  case evaluated
14
14
  when Parser::AST::Node
@@ -38,10 +38,10 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
38
38
  when NilClass
39
39
  'nil'
40
40
  else
41
- raise Synvert::Core::MethodNotSupported, "rewritten_source is not handled for #{evaluated.inspect}"
41
+ raise "rewritten_source is not handled for #{evaluated.inspect}"
42
42
  end
43
- else
44
- "{{#{old_code}}}"
43
+ rescue StandardError => e
44
+ raise "can not parse \"#{code}\""
45
45
  end
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.4.4"
4
+ VERSION = "1.5.1"
5
5
  end
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.
@@ -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.4
4
+ version: 1.5.1
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-09-26 00:00:00.000000000 Z
11
+ date: 2022-10-19 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.7
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