ruby2ruby 2.0.3 → 2.0.4

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.
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- BU'�i~P�=��A�a���i�>�Mlf$���*c83ѝ,���B
2
- ١�k��U�ẋl�J�<���t
3
- Iwh�Jqᵦ���A
4
- ���ά}ê�.N�#��x [5V$�z�6��ta��[<�4N�bl��!���;�mw0�Tz]�sb��U�gkkClqj&�8���j�bƂ��D%n�4�z�������� �"-�_7aJ�y�G�0�G��7����=�B�!�ɂɑ�=N�/�w�
1
+ }�*5ܡ߂�:�|�u#a=�M��'��"\Zؾ"d!��,g�s=~:.�Wc6pP’�%~w��z�� �����6����������RD+�+A�j$�Y~�8L�9��K1>������Ša��R��1g��8c����eY�蘷놓�"ȳ�;u�R�85�ͫn\�P��7��6��̦�����2636�M�aC���xQ�,�^��dt���;5ʬI8J7.ꂰ�؟$��Jߥ�%��DFE��K� �9y� ��
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.0.4 / 2013-03-28
2
+
3
+ * 1 bug fix:
4
+
5
+ * Fixed attr_* generators in cases where the body isn't idiomatic. (robertfeldt)
6
+
1
7
  === 2.0.3 / 2013-02-07
2
8
 
3
9
  * 2 minor enhancements:
data/lib/ruby2ruby.rb CHANGED
@@ -24,7 +24,7 @@ class Regexp
24
24
  end
25
25
 
26
26
  class Ruby2Ruby < SexpProcessor
27
- VERSION = '2.0.3'
27
+ VERSION = "2.0.4"
28
28
  LINE_LENGTH = 78
29
29
 
30
30
  BINARY = [:<=>, :==, :<, :>, :<=, :>=, :-, :+, :*, :/, :%, :<<, :>>, :**]
@@ -315,15 +315,34 @@ class Ruby2Ruby < SexpProcessor
315
315
  type1 = exp[1].first
316
316
  type2 = exp[2].first rescue nil
317
317
 
318
- if type1 == :args and [:ivar, :attrset].include? type2 then
319
- name = exp.shift
318
+ if type1 == :args and [:ivar, :iasgn, :attrset].include? type2 then
319
+ name = exp.first # don't shift in case we pass through
320
320
  case type2
321
321
  when :ivar then
322
- exp.clear
323
- return "attr_reader #{name.inspect}"
322
+ ivar_name = exp.ivar.last
323
+
324
+ meth_name = ivar_name.to_s[1..-1].to_sym
325
+ expected = s(meth_name, s(:args), s(:ivar, ivar_name))
326
+
327
+ if exp == expected then
328
+ exp.clear
329
+ return "attr_reader #{name.inspect}"
330
+ end
324
331
  when :attrset then
332
+ # TODO: deprecate? this is a PT relic
325
333
  exp.clear
326
334
  return "attr_writer :#{name.to_s[0..-2]}"
335
+ when :iasgn then
336
+ ivar_name = exp.iasgn[1]
337
+ meth_name = "#{ivar_name.to_s[1..-1]}=".to_sym
338
+ arg_name = exp.args.last
339
+ expected = s(meth_name, s(:args, arg_name),
340
+ s(:iasgn, ivar_name, s(:lvar, arg_name)))
341
+
342
+ if exp == expected then
343
+ exp.clear
344
+ return "attr_writer :#{name.to_s[0..-2]}"
345
+ end
327
346
  else
328
347
  raise "Unknown defn type: #{exp.inspect}"
329
348
  end
@@ -80,6 +80,42 @@ class TestRuby2Ruby < R2RTestCase
80
80
  util_compare inn, out
81
81
  end
82
82
 
83
+ def test_attr_reader_diff
84
+ inn = s(:defn, :same, s(:args), s(:ivar, :@diff))
85
+ out = "def same\n @diff\nend"
86
+ util_compare inn, out
87
+ end
88
+
89
+ def test_attr_reader_same
90
+ inn = s(:defn, :same, s(:args), s(:ivar, :@same))
91
+ out = "attr_reader :same"
92
+ util_compare inn, out
93
+ end
94
+
95
+ def test_attr_reader_same_name_diff_body
96
+ inn = s(:defn, :same, s(:args), s(:not, s(:ivar, :@same)))
97
+ out = "def same\n (not @same)\nend"
98
+ util_compare inn, out
99
+ end
100
+
101
+ def test_attr_writer_diff
102
+ inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@diff, s(:lvar, :o)))
103
+ out = "def same=(o)\n @diff = o\nend"
104
+ util_compare inn, out
105
+ end
106
+
107
+ def test_attr_writer_same_name_diff_body
108
+ inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same, s(:lit, 42)))
109
+ out = "def same=(o)\n @same = 42\nend"
110
+ util_compare inn, out
111
+ end
112
+
113
+ def test_attr_writer_same
114
+ inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same , s(:lvar, :o)))
115
+ out = "attr_writer :same"
116
+ util_compare inn, out
117
+ end
118
+
83
119
  def test_dregx_slash
84
120
  inn = util_thingy(:dregx)
85
121
  out = '/a"b#{(1 + 1)}c"d\/e/'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 3
10
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2013-02-07 00:00:00 Z
39
+ date: 2013-03-28 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sexp_processor
@@ -76,11 +76,11 @@ dependencies:
76
76
  requirements:
77
77
  - - ~>
78
78
  - !ruby/object:Gem::Version
79
- hash: 17
79
+ hash: 21
80
80
  segments:
81
81
  - 4
82
- - 5
83
- version: "4.5"
82
+ - 7
83
+ version: "4.7"
84
84
  type: :development
85
85
  version_requirements: *id003
86
86
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- �ҟAd�����I����L��L9���Q�*��oqu��Β�pS���f%�SGCt�L�:�
2
- Zut�+yh5e�PQ���R�����&)��4 '���;Rѵ�KL��{���$�W���k� A0�x���C?Wܔ�EK��鴳��8��<k��|��}~4Ƌ�R����ܽo$��A`d$&�ǡ�����W�e�עz<N"�
1
+ V��>\5{j[�������{
2
+ �Ԑ8Ed[�4p�`�BhZ������=Ĵ -J�� 9���]۹�������ENE#ō�S��%�L�C��RsOB��Ll��t��^����id�#j��~�[OD���S~e��b�F.RGI��;f��
3
+ �:|��)��ܝ��'�[��8G��a��F���������2���)�l�L�[Q�y���X�ӠDN�0��Wj"�ڄd3�LЭ�