synvert-core 0.9.1 → 0.10.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/.travis.yml +1 -3
- data/CHANGELOG.md +4 -2
- data/lib/synvert/core/rewriter/action.rb +10 -2
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +1 -1
- data/lib/synvert/core/rewriter/gem_spec.rb +1 -1
- data/lib/synvert/core/rewriter/instance.rb +12 -8
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/action/append_action_spec.rb +1 -1
- data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +4 -4
- data/spec/synvert/core/rewriter/instance_spec.rb +4 -4
- data/synvert-core.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4282ee9f0e489971000bf8cedfc613d9fc44c11
|
4
|
+
data.tar.gz: 0f27f2a20c1f7a111692436d86c4b10f2d9790f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564a1c66e905b84e830a8f8a782336ba0b4640962ebbd7dea6d3fd04c0817d87d90061a5e596d953ff3c5bc3973563ab06e65666fca95146450b4871e81de3f4
|
7
|
+
data.tar.gz: b701564b0eff45f5d9bc439f524946929e31d5b9da10547c24593861f46c0c88cf3ea98ac61af66071a0f6be9daf4537ac5178fcbddb2930d6f60fe3f879652a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
10
|
-
|
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. {
|
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
|
-
|
208
|
-
|
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
|
-
|
216
|
-
|
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
|
-
|
224
|
-
|
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
|
-
|
232
|
-
|
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
|
data/lib/synvert/core/version.rb
CHANGED
@@ -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
|
-
|
48
|
-
|
49
|
-
|
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.
|
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.
|
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:
|
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.
|
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.
|
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.
|
213
|
+
rubygems_version: 2.5.1
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: convert ruby code to better syntax.
|