synvert-core 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 908d88152aaea79eafba824db6d91351f6b02394
4
- data.tar.gz: b68026829b49fd6a6b78295f8c8abae77a0812b2
3
+ metadata.gz: 2eacc4ed46475f1e8f697a68f0014a51f8652a6a
4
+ data.tar.gz: c2ca725e2348c8bb4cc4ee06fd05eb3d82b2eb53
5
5
  SHA512:
6
- metadata.gz: b5bbe05c11edcc9b1f4688f962850851b07a9e5a2a01871f8455a3213823ff15a565c686e73eae92f6045eba29f810993a2e4a2ab1cecc5340b5838e707b728f
7
- data.tar.gz: 5808b8122edd185de72864ac178e64bae3888a8be284774bd3e5bc274dfebc43d6280978d98d4d91e8046503f5dd94c4bfe06bd8149e6cf766f529f792ddcb1f
6
+ metadata.gz: 3ee88f43b7986394ed519e0e94364d9a603dac40bd61f25ec83f661beb52ace2036586e19df6ccf0e99e894b4dbe1c0f0123b83fd1bb52af7c8ff03a336f6875
7
+ data.tar.gz: 9c17ea44d83d5f885fbc1a6ad08bba5d9d8d551d2b163010d35c9e59127ce11db8472e7751cef67d7ab70cbb1ac0be7c6e79a99f62f8dd50d92c24b9386fae98
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.1
4
+
5
+ * Remove Rewriter::Instance class methods current and current_source
6
+
3
7
  ## 0.5.0 (2014-08-21)
4
8
 
5
9
  * Add group to rewriter
@@ -209,9 +209,8 @@ class Parser::AST::Node
209
209
  #
210
210
  # @return [String] source code.
211
211
  def to_source
212
- instance = Synvert::Rewriter::Instance.current
213
212
  if self.loc.expression
214
- instance.current_source[self.loc.expression.begin_pos...self.loc.expression.end_pos]
213
+ self.loc.expression.source
215
214
  end
216
215
  end
217
216
 
@@ -271,8 +270,7 @@ class Parser::AST::Node
271
270
  evaluated = self.instance_eval old_code
272
271
  case evaluated
273
272
  when Parser::AST::Node
274
- source = evaluated.loc.expression.source_buffer.source
275
- source[evaluated.loc.expression.begin_pos...evaluated.loc.expression.end_pos]
273
+ evaluated.loc.expression.source
276
274
  when Array
277
275
  if evaluated.size > 0
278
276
  source = evaluated.first.loc.expression.source_buffer.source
@@ -236,7 +236,7 @@ module Synvert::Core
236
236
  # @return [Integer] begin position.
237
237
  def begin_pos
238
238
  node_begin_pos = @node.loc.expression.begin_pos
239
- while @instance.current_source[node_begin_pos -= 1] == ' '
239
+ while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' '
240
240
  end
241
241
  node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1
242
242
  end
@@ -246,9 +246,8 @@ module Synvert::Core
246
246
  # @return [Integer] end position.
247
247
  def end_pos
248
248
  node_begin_pos = @node.loc.expression.begin_pos
249
- node_end_pos = @node.loc.expression.end_pos
250
- node_begin_pos += @instance.current_source[node_begin_pos..node_end_pos].index "do"
251
- while @instance.current_source[node_begin_pos += 1] != '@'
249
+ node_begin_pos += @node.loc.expression.source.index "do"
250
+ while @node.loc.expression.source_buffer.source[node_begin_pos += 1] != '@'
252
251
  end
253
252
  node_begin_pos
254
253
  end
@@ -257,7 +256,7 @@ module Synvert::Core
257
256
  #
258
257
  # @return [String] rewritten code.
259
258
  def rewritten_code
260
- @instance.current_source[begin_pos...end_pos].sub(Engine::ERUBY_STMT_SPLITTER, "@output_buffer.append= ")
259
+ @node.loc.expression.source_buffer.source[begin_pos...end_pos].sub(Engine::ERUBY_STMT_SPLITTER, "@output_buffer.append= ")
261
260
  .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER)
262
261
  end
263
262
  end
@@ -9,10 +9,6 @@ module Synvert::Core
9
9
  include Rewriter::Helper
10
10
 
11
11
  class <<self
12
- # @!attribute [rw] current
13
- # @return current instance
14
- attr_accessor :current
15
-
16
12
  # Cached file source.
17
13
  #
18
14
  # @param file_path [String] file path
@@ -64,11 +60,9 @@ module Synvert::Core
64
60
 
65
61
  # @!attribute [rw] current_node
66
62
  # @return current parsing node
67
- # @!attribute [rw] current_source
68
- # @return current source code of file
69
63
  # @!attribute [rw] current_file
70
64
  # @return current filename
71
- attr_accessor :current_node, :current_source, :current_file
65
+ attr_accessor :current_node, :current_file
72
66
 
73
67
  # Initialize an instance.
74
68
  #
@@ -88,8 +82,6 @@ module Synvert::Core
88
82
  # It finds all files, for each file, it executes the block code, gets all rewrite actions,
89
83
  # and rewrite source code back to original file.
90
84
  def process
91
- self.class.current = self
92
-
93
85
  file_pattern = File.join(Configuration.instance.get(:path), @file_pattern)
94
86
  Dir.glob(file_pattern).each do |file_path|
95
87
  unless Configuration.instance.get(:skip_files).include? file_path
@@ -99,7 +91,6 @@ module Synvert::Core
99
91
  ast = self.class.file_ast(file_path)
100
92
 
101
93
  @current_file = file_path
102
- @current_source = source
103
94
 
104
95
  self.process_with_node ast do
105
96
  instance_eval &@block
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  end
7
7
  end
@@ -56,8 +56,6 @@ describe Parser::AST::Node do
56
56
  it 'gets for block node' do
57
57
  source = 'RSpec.configure do |config|; end'
58
58
  node = parse(source)
59
- instance = double(current_source: source)
60
- Synvert::Rewriter::Instance.current = instance
61
59
  expect(node.arguments.map { |argument| argument.to_source }).to eq ['config']
62
60
  end
63
61
 
@@ -192,8 +190,6 @@ describe Parser::AST::Node do
192
190
  describe '#to_source' do
193
191
  it 'gets for node' do
194
192
  source = 'params[:user][:email]'
195
- instance = double(current_source: source)
196
- Synvert::Rewriter::Instance.current = instance
197
193
  node = parse(source)
198
194
  expect(node.to_source).to eq 'params[:user][:email]'
199
195
  end
@@ -223,53 +219,45 @@ describe Parser::AST::Node do
223
219
  rewriter = Synvert::Rewriter.new('foo', 'bar')
224
220
  Synvert::Rewriter::Instance.new(rewriter, 'file pattern')
225
221
  }
226
- before { Synvert::Rewriter::Instance.current = instance }
227
222
 
228
223
  it 'matches class name' do
229
224
  source = 'class Synvert; end'
230
- instance.current_source = source
231
225
  node = parse(source)
232
226
  expect(node).to be_match(type: 'class', name: 'Synvert')
233
227
  end
234
228
 
235
229
  it 'matches message with regexp' do
236
230
  source = 'User.find_by_login(login)'
237
- instance.current_source = source
238
231
  node = parse(source)
239
232
  expect(node).to be_match(type: 'send', message: /^find_by_/)
240
233
  end
241
234
 
242
235
  it 'matches arguments with symbol' do
243
236
  source = 'params[:user]'
244
- instance.current_source = source
245
237
  node = parse(source)
246
238
  expect(node).to be_match(type: 'send', receiver: 'params', message: '[]', arguments: [:user])
247
239
  end
248
240
 
249
241
  it 'matches assign number' do
250
242
  source = 'at_least(0)'
251
- instance.current_source = source
252
243
  node = parse(source)
253
244
  expect(node).to be_match(type: 'send', arguments: [0])
254
245
  end
255
246
 
256
247
  it 'matches arguments with string' do
257
248
  source = 'params["user"]'
258
- instance.current_source = source
259
249
  node = parse(source)
260
250
  expect(node).to be_match(type: 'send', receiver: 'params', message: '[]', arguments: ['user'])
261
251
  end
262
252
 
263
253
  it 'matches arguments any' do
264
254
  source = 'config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false'
265
- instance.current_source = source
266
255
  node = parse(source)
267
256
  expect(node).to be_match(type: 'send', arguments: {any: 'Lifo::Cache'})
268
257
  end
269
258
 
270
259
  it 'matches not' do
271
260
  source = 'class Synvert; end'
272
- instance.current_source = source
273
261
  node = parse(source)
274
262
  expect(node).not_to be_match(type: 'class', name: {not: 'Synvert'})
275
263
  end
@@ -280,18 +268,15 @@ describe Parser::AST::Node do
280
268
  rewriter = Synvert::Rewriter.new('foo', 'bar')
281
269
  Synvert::Rewriter::Instance.new(rewriter, 'file pattern')
282
270
  }
283
- before { Synvert::Rewriter::Instance.current = instance }
284
271
 
285
272
  it 'does not rewrite with unknown method' do
286
273
  source = 'class Synvert; end'
287
- instance.current_source = source
288
274
  node = parse(source)
289
275
  expect(node.rewritten_source('{{foobar}}')).to eq '{{foobar}}'
290
276
  end
291
277
 
292
278
  it 'rewrites with node known method' do
293
279
  source = 'class Synvert; end'
294
- instance.current_source = source
295
280
  node = parse(source)
296
281
  expect(node.rewritten_source('{{name}}')).to eq 'Synvert'
297
282
  end
@@ -11,8 +11,7 @@ module Synvert::Core
11
11
  """
12
12
  }
13
13
  let(:node) { Parser::CurrentRuby.parse(source) }
14
- let(:instance) { double(:current_node => node, :current_source => source) }
15
- before { Rewriter::Instance.current = instance }
14
+ let(:instance) { double(:current_node => node) }
16
15
 
17
16
  describe Rewriter::IfExistCondition do
18
17
  describe '#process' do
@@ -67,8 +66,7 @@ module Synvert::Core
67
66
  end
68
67
  """
69
68
  node = Parser::CurrentRuby.parse(source)
70
- instance = double(:current_node => node, :current_source => source)
71
- Rewriter::Instance.current = instance
69
+ instance = double(:current_node => node)
72
70
  run = false
73
71
  condition = Rewriter::IfOnlyExistCondition.new instance, type: 'send', message: 'include', arguments: ['EmailSpec::Helpers'] do
74
72
  run = true
@@ -17,11 +17,8 @@ end
17
17
  """
18
18
  }
19
19
  let(:node) { Parser::CurrentRuby.parse(source) }
20
- let(:instance) { double(:current_node => node, :current_node= => node, :current_source => source) }
21
- before do
22
- allow(instance).to receive(:process_with_node).and_yield
23
- Rewriter::Instance.current = instance
24
- end
20
+ let(:instance) { double(:current_node => node, :current_node= => node) }
21
+ before { allow(instance).to receive(:process_with_node).and_yield }
25
22
 
26
23
  describe '#process' do
27
24
  it 'not call block if no matching node' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser