syntax_tree_ext 0.6.4 → 0.7.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: 6983ce67c837c77fb232bcb11b8319e1f358126b746fdceb9bb586c01eaad408
4
- data.tar.gz: 9cda7bf847292a641816b4ff5d6b2167e3717b9534aa0c1eaa16565ef6022204
3
+ metadata.gz: 76f93356ad00c2206f575f6aa8117de178eb2710a6534f8df11c10871f68a9b8
4
+ data.tar.gz: a846f03d2f62bf8928764a6423df58ded2b1f524cf677c886f069f9e835cc7e9
5
5
  SHA512:
6
- metadata.gz: 1d504bd7d7f7609bd7bd26726bf2e4dfd1035ee9a16462430e32251225a867894a46d6422c0021e469a317fb2dd6b900d700fc43238bb22c6fde456e83e4cad4
7
- data.tar.gz: 85c22b4a59294845ff959cc40f0667475405fde09e4a53fcc39331320f557dff2c037dc713b2bd4be8b8601023fc96e8c885a83770f22e008973bbf61f48f68e
6
+ metadata.gz: 7e677f857fe5e663a92d2e2905535647ce0c4c6927da6a151a1ab88fd7c3265d465efba409cd4147c7c20486e7aedde93cb7bfa715c00f19d499708bfb5ae17e
7
+ data.tar.gz: f9b15130df4786bb1b9548ea3d21eb234508270c38599b80cf01600fa7cd8de8c6150283c6e1e13bb69975b5aea6ad0535410fc952d8013963921ec4926efd7b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.7.1 (2024-02-11)
4
+
5
+ * Reuse `respond_to_assocs`
6
+
7
+ ## 0.7.0 (2024-02-10)
8
+
9
+ * Remove `to_hash` extend
10
+ * Remove `siblings` method
11
+ * Hack `SyntaxTree.parse` instead of `SyntaxTree::Parser.parse`
12
+
3
13
  ## 0.6.4 (2023-08-17)
4
14
 
5
15
  * `to_value` supports for empty array
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree_ext (0.6.4)
4
+ syntax_tree_ext (0.7.1)
5
5
  syntax_tree
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxTreeExt
4
- VERSION = "0.6.4"
4
+ VERSION = "0.7.1"
5
5
  end
@@ -18,11 +18,11 @@ module SyntaxTreeExt
18
18
  end
19
19
 
20
20
  module SyntaxTree
21
- class Parser
21
+ class << self
22
22
  alias_method :original_parse, :parse
23
23
 
24
- def parse
25
- node = original_parse
24
+ def parse(source)
25
+ node = original_parse(source)
26
26
  node.set_parent_node_and_source(source)
27
27
  node
28
28
  end
@@ -50,19 +50,8 @@ module SyntaxTree
50
50
  end
51
51
  end
52
52
 
53
- def siblings
54
- child_nodes = parent_node.deconstruct_keys([]).except(:location, :comments).values
55
- if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
56
- index = child_nodes.first.index(self)
57
- return child_nodes.first[index + 1...]
58
- end
59
-
60
- index = child_nodes.index(self)
61
- child_nodes[index + 1...]
62
- end
63
-
64
53
  def keys
65
- if is_a?(BareAssocHash) || is_a?(HashLiteral)
54
+ if respond_to_assocs?
66
55
  assocs.map(&:key)
67
56
  else
68
57
  raise MethodNotSupported, "keys is not supported for #{self}"
@@ -70,7 +59,7 @@ module SyntaxTree
70
59
  end
71
60
 
72
61
  def values
73
- if is_a?(BareAssocHash) || is_a?(HashLiteral)
62
+ if respond_to_assocs?
74
63
  assocs.map(&:value)
75
64
  else
76
65
  raise MethodNotSupported, "values is not supported for #{self}"
@@ -78,7 +67,7 @@ module SyntaxTree
78
67
  end
79
68
 
80
69
  def hash_assoc(key)
81
- if is_a?(BareAssocHash) || is_a?(HashLiteral)
70
+ if respond_to_assocs?
82
71
  assocs.find { |assoc_node| assoc_node.key.to_value == key }
83
72
  else
84
73
  raise MethodNotSupported, "hash_assoc is not supported for #{self}"
@@ -86,7 +75,7 @@ module SyntaxTree
86
75
  end
87
76
 
88
77
  def hash_value(key)
89
- if is_a?(BareAssocHash) || is_a?(HashLiteral)
78
+ if respond_to_assocs?
90
79
  assocs.find { |assoc_node| assoc_node.key.to_value == key }&.value
91
80
  else
92
81
  raise MethodNotSupported, "hash_value is not supported for #{self}"
@@ -120,27 +109,6 @@ module SyntaxTree
120
109
  source[location.start_char...location.end_char]
121
110
  end
122
111
 
123
- # Convert node to a hash, so that it can be converted to a json.
124
- def to_hash
125
- result = { node_type: self.class.name.split('::').last }
126
- unless deconstruct_keys([]).empty?
127
- deconstruct_keys([]).each do |key, value|
128
- result[key] =
129
- case value
130
- when Array
131
- value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
132
- when SyntaxTree::Node, SyntaxTree::Location
133
- value.to_hash
134
- else
135
- value
136
- end
137
- end
138
- else
139
- result[:children] = children.map { |c| c.respond_to?(:to_hash) ? c.to_hash : c }
140
- end
141
- result
142
- end
143
-
144
112
  # Respond key value and source for hash node
145
113
  def method_missing(method_name, *args, &block)
146
114
  return super unless respond_to_assocs?
@@ -187,17 +155,4 @@ module SyntaxTree
187
155
  assoc_key.end_with?(':') ? assoc_key == "#{key}:" : assoc_key == key
188
156
  end
189
157
  end
190
-
191
- class Location
192
- def to_hash
193
- {
194
- start_line: start_line,
195
- start_char: start_char,
196
- start_column: start_column,
197
- end_line: end_line,
198
- end_char: end_char,
199
- end_column: end_column,
200
- }
201
- end
202
- end
203
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.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: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.4.18
64
+ rubygems_version: 3.5.3
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: extend syntax_tree