synvert-core 0.4.0 → 0.4.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
  SHA1:
3
- metadata.gz: e006c23fc6ca2d1398bfaf32db73c4ced664a94e
4
- data.tar.gz: d7dc0a2a30fb4e544f4bd25307b4177ed6914f38
3
+ metadata.gz: 9a3cff654eae485c77411077c8e1ee126a29afb6
4
+ data.tar.gz: 21dcd6b6f868b4ccc9c35176578d01a060971e4c
5
5
  SHA512:
6
- metadata.gz: c05837b831a3c9aa02c1c0bd5a88adeeddafd98114a562462749d3f92a4728b0fd1e38415cd26d7816a46705c5528285a33705c480018abdb59fb9a9c82d01bd
7
- data.tar.gz: 857e3cbd4cfc5ca0c77dc452e615a23006436418c600b09c6738dbee267abbb71042ddbc1a2b7a0b65f531cef0b24811ee19b8fa6edfa97ef9043a32cd77a025
6
+ metadata.gz: 3ae01938e470eba926eaaa5d7564bdf2342ad6138938c67c400540f99872dcadf42fb5eb4363623edf133da1870c62b94cf12bf5112da01961730f561341ae5e
7
+ data.tar.gz: dab94a1c780431350248d454331144c72a11b4e26e63431a5fe9c5fc03f79f35d7cab1928ec9bf897ce7133a35b849005784120c0ec43008d8216ca5c4d90289
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.1
4
+
5
+ * add Rewriter::Helper module to provide common helper methods.
6
+
3
7
  ## 0.4.0 (2014-07-26)
4
8
 
5
9
  * Add erb support
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ module Synvert::Core
4
+ # Rewriter::Helper provides some helper methods to make it easier to write a snippet.
5
+ module Rewriter::Helper
6
+ # Add receiver to code if necessary.
7
+ #
8
+ # @param code [String] old code
9
+ # @return [String] new code
10
+ #
11
+ # @example
12
+ #
13
+ # add_receiver_if_necessary("{{message}} {{arguments}}")
14
+ #
15
+ # if current_node doesn't have a receiver, it returns "{{message}} {{arguments}}"
16
+ # if current_node has a receiver, it returns "{{receiver}}.{{message}} {{arguments}}"
17
+ def add_receiver_if_necessary(code)
18
+ if node.receiver
19
+ "{{receiver}}.#{code}"
20
+ else
21
+ code
22
+ end
23
+ end
24
+
25
+ # Remove leading and trailing brackets.
26
+ #
27
+ # @param code [String] old code
28
+ # @return [String] new code
29
+ #
30
+ # @example
31
+ #
32
+ # strip_brackets("(1..100)") #=> "1..100"
33
+ def strip_brackets(code)
34
+ code.sub(/^[{(\[]/, '').sub(/[})\]]$/, '')
35
+ end
36
+ end
37
+ end
@@ -6,6 +6,8 @@ module Synvert::Core
6
6
  #
7
7
  # One instance can contains one or many [Synvert::Core::Rewriter::Scope] and [Synvert::Rewriter::Condition].
8
8
  class Rewriter::Instance
9
+ include Rewriter::Helper
10
+
9
11
  class <<self
10
12
  attr_accessor :current
11
13
  end
@@ -35,6 +35,8 @@ module Synvert::Core
35
35
  autoload :UnlessExistCondition, 'synvert/core/rewriter/condition'
36
36
  autoload :IfOnlyExistCondition, 'synvert/core/rewriter/condition'
37
37
 
38
+ autoload :Helper, 'synvert/core/rewriter/helper'
39
+
38
40
  autoload :GemSpec, 'synvert/core/rewriter/gem_spec'
39
41
 
40
42
  class <<self
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
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.0
4
+ version: 0.4.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-07-26 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -119,6 +119,7 @@ files:
119
119
  - lib/synvert/core/rewriter/action.rb
120
120
  - lib/synvert/core/rewriter/condition.rb
121
121
  - lib/synvert/core/rewriter/gem_spec.rb
122
+ - lib/synvert/core/rewriter/helper.rb
122
123
  - lib/synvert/core/rewriter/instance.rb
123
124
  - lib/synvert/core/rewriter/scope.rb
124
125
  - lib/synvert/core/rewriter/warning.rb