synvert-core 0.9.1 → 0.10.0

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
  SHA1:
3
- metadata.gz: 83e76b23b2cfae3cb97168b6b50c19c630f5c5f6
4
- data.tar.gz: 4f3ea5b48592b17a5ed7bccf54a0dcb032aab24f
3
+ metadata.gz: b4282ee9f0e489971000bf8cedfc613d9fc44c11
4
+ data.tar.gz: 0f27f2a20c1f7a111692436d86c4b10f2d9790f9
5
5
  SHA512:
6
- metadata.gz: a43634427747700cc195fe0f1c15af818e98ca21fa081468c4d2666ab5b3c0657acab9eec6ebb255be87ed9c0501624b4ec4c8a13392610e26ebf969cda2a91a
7
- data.tar.gz: c73b695d4cf990ab4bcc8a9542739edf7e4e61685aa1e3c9b5be5d7ade63031ed10b3f56c1adfc6a1d9ac53919b8261f148de914dd98e7177d1f0a507523f31a
6
+ metadata.gz: 564a1c66e905b84e830a8f8a782336ba0b4640962ebbd7dea6d3fd04c0817d87d90061a5e596d953ff3c5bc3973563ab06e65666fca95146450b4871e81de3f4
7
+ data.tar.gz: b701564b0eff45f5d9bc439f524946929e31d5b9da10547c24593861f46c0c88cf3ea98ac61af66071a0f6be9daf4537ac5178fcbddb2930d6f60fe3f879652a
data/.travis.yml CHANGED
@@ -1,5 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
3
+ - 2.3.1
data/CHANGELOG.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.9.1
3
+ ## 0.10.0 (2016-07-31)
4
4
 
5
- * Use parser 2.3.0.pre.4
5
+ * Use parser 2.3.1.2
6
+ * Add options to Rewriter::Action
7
+ * Add autoindent option
6
8
 
7
9
  ## 0.9.0 (2015-12-23)
8
10
 
@@ -6,10 +6,12 @@ module Synvert::Core
6
6
  # Initialize an action.
7
7
  #
8
8
  # @param instance [Synvert::Core::Rewriter::Instance]
9
- # @param code {String] new code to add, replace or remove.
10
- def initialize(instance, code)
9
+ # @param code [String] new code to add, replace or remove.
10
+ # @param options [Hash] action options, it includes :autoindent.
11
+ def initialize(instance, code, options={})
11
12
  @instance = instance
12
13
  @code = code
14
+ @options = default_options.merge(options)
13
15
  @node = @instance.current_node
14
16
  end
15
17
 
@@ -47,6 +49,12 @@ module Synvert::Core
47
49
  def <=>(action)
48
50
  self.begin_pos <=> action.begin_pos
49
51
  end
52
+
53
+ private
54
+
55
+ def default_options
56
+ { autoindent: true }
57
+ end
50
58
  end
51
59
  end
52
60
 
@@ -24,7 +24,7 @@ module Synvert::Core
24
24
  if rewritten_source.split("\n").length > 1
25
25
  new_code = []
26
26
  rewritten_source.split("\n").each_with_index { |line, index|
27
- new_code << (index == 0 ? line : indent(@node) + line)
27
+ new_code << (index == 0 || !@options[:autoindent] ? line : indent(@node) + line)
28
28
  }
29
29
  new_code.join("\n")
30
30
  else
@@ -8,7 +8,7 @@ module Synvert::Core
8
8
  # Initialize a gem_spec.
9
9
  #
10
10
  # @param name [String] gem name
11
- # @param comparator [Hash] comparator to gem version, e.g. {eg: '2.0.0'},
11
+ # @param comparator [Hash] comparator to gem version, e.g. {eq: '2.0.0'},
12
12
  # comparator key can be eq, lt, gt, lte, gte or ne.
13
13
  def initialize(name, comparator)
14
14
  @name = name
@@ -204,32 +204,36 @@ module Synvert::Core
204
204
  # append the code to the bottom of current node body.
205
205
  #
206
206
  # @param code [String] code need to be appended.
207
- def append(code)
208
- @actions << Rewriter::AppendAction.new(self, code)
207
+ # @param options [Hash] action options.
208
+ def append(code, options={})
209
+ @actions << Rewriter::AppendAction.new(self, code, options)
209
210
  end
210
211
 
211
212
  # Parse insert dsl, it creates a [Synvert::Core::Rewriter::InsertAction] to
212
213
  # insert the code to the top of current node body.
213
214
  #
214
215
  # @param code [String] code need to be inserted.
215
- def insert(code)
216
- @actions << Rewriter::InsertAction.new(self, code)
216
+ # @param options [Hash] action options.
217
+ def insert(code, options={})
218
+ @actions << Rewriter::InsertAction.new(self, code, options)
217
219
  end
218
220
 
219
221
  # Parse insert_after dsl, it creates a [Synvert::Core::Rewriter::InsertAfterAction] to
220
222
  # insert the code next to the current node.
221
223
  #
222
224
  # @param code [String] code need to be inserted.
223
- def insert_after(node)
224
- @actions << Rewriter::InsertAfterAction.new(self, node)
225
+ # @param options [Hash] action options.
226
+ def insert_after(node, options={})
227
+ @actions << Rewriter::InsertAfterAction.new(self, node, options)
225
228
  end
226
229
 
227
230
  # Parse replace_with dsl, it creates a [Synvert::Core::Rewriter::ReplaceWithAction] to
228
231
  # replace current node with code.
229
232
  #
230
233
  # @param code [String] code need to be replaced with.
231
- def replace_with(code)
232
- @actions << Rewriter::ReplaceWithAction.new(self, code)
234
+ # @param options [Hash] action options.
235
+ def replace_with(code, options={})
236
+ @actions << Rewriter::ReplaceWithAction.new(self, code, options)
233
237
  end
234
238
 
235
239
  # Parse replace_erb_stmt_with_expr dsl, it creates a [Synvert::Core::Rewriter::ReplaceErbStmtWithExprAction] to
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = "0.9.1"
5
+ VERSION = "0.10.0"
6
6
  end
7
7
  end
@@ -11,7 +11,7 @@ module Synvert::Core
11
11
  end
12
12
 
13
13
  it 'gets begin_pos' do
14
- expect(subject.begin_pos).to eq "calss User\n has_many :posts".length
14
+ expect(subject.begin_pos).to eq "class User\n has_many :posts".length
15
15
  end
16
16
 
17
17
  it 'gets end_pos' do
@@ -31,7 +31,7 @@ module Synvert::Core
31
31
  Rewriter::ReplaceWithAction.new(instance, """describe '#size' do
32
32
  subject { super().size }
33
33
  it { {{body}} }
34
- end""")
34
+ end""", autoindent: false)
35
35
  }
36
36
 
37
37
  it 'gets begin_pos' do
@@ -44,9 +44,9 @@ end""")
44
44
 
45
45
  it 'gets rewritten_code' do
46
46
  expect(subject.rewritten_code).to eq """describe '#size' do
47
- subject { super().size }
48
- it { should == 1 }
49
- end"""
47
+ subject { super().size }
48
+ it { should == 1 }
49
+ end"""
50
50
  end
51
51
  end
52
52
  end
@@ -58,22 +58,22 @@ module Synvert::Core
58
58
  end
59
59
 
60
60
  it 'parses append' do
61
- expect(Rewriter::AppendAction).to receive(:new).with(instance, 'include FactoryGirl::Syntax::Methods')
61
+ expect(Rewriter::AppendAction).to receive(:new).with(instance, 'include FactoryGirl::Syntax::Methods', {})
62
62
  instance.append "include FactoryGirl::Syntax::Methods"
63
63
  end
64
64
 
65
65
  it 'parses insert' do
66
- expect(Rewriter::InsertAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods')
66
+ expect(Rewriter::InsertAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods', {})
67
67
  instance.insert "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
68
68
  end
69
69
 
70
70
  it 'parses insert_after' do
71
- expect(Rewriter::InsertAfterAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods')
71
+ expect(Rewriter::InsertAfterAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods', {})
72
72
  instance.insert_after "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
73
73
  end
74
74
 
75
75
  it 'parses replace_with' do
76
- expect(Rewriter::ReplaceWithAction).to receive(:new).with(instance, 'create {{arguments}}')
76
+ expect(Rewriter::ReplaceWithAction).to receive(:new).with(instance, 'create {{arguments}}', {})
77
77
  instance.replace_with 'create {{arguments}}'
78
78
  end
79
79
 
data/synvert-core.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "parser", "2.3.0.pre.4"
21
+ spec.add_runtime_dependency "parser", "2.3.1.2"
22
22
  spec.add_runtime_dependency "activesupport"
23
23
  spec.add_runtime_dependency "erubis"
24
24
 
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.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.0.pre.4
19
+ version: 2.3.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.0.pre.4
26
+ version: 2.3.1.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.4.5.1
213
+ rubygems_version: 2.5.1
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: convert ruby code to better syntax.