Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 58 lines (49 sloc) 1.642 kB
790a1aa @johnynek Initial Import
johnynek authored
1 #!/usr/bin/env ruby
2
3 $indent = " "
4
5 def make_tuple_conv(cnt)
6 type_names = ('A'..'Z').to_a[0...cnt]
7 indices = (0...cnt).to_a
8 comma_tn = type_names.join(",")
9 getters = type_names.map { |n|
10 #" g#{n} : TupleGetter[#{n}]"
11 " g#{n} : TupleGetter[#{n}]"
12 }.join(",\n#{$indent}")
13 typed_args = type_names.zip(indices).map { |n,ni|
14 "g#{n}.get(tup, #{ni})"
15 }.join(",\n#{$indent} ")
16 %Q|\n#{$indent}implicit def tuple#{cnt}Converter[#{comma_tn}](implicit
17 #{$indent}#{getters}) = new TupleConverter[Tuple#{cnt}[#{comma_tn}]]{
39e2e52 @johnynek Refactors TupleConverter to apply with TupleEntry
johnynek authored
18 #{$indent} def apply(te : TupleEntry) = {
19 #{$indent} val tup = te.getTuple
790a1aa @johnynek Initial Import
johnynek authored
20 #{$indent} Tuple#{cnt}(#{typed_args})
21 #{$indent} }
22 #{$indent} def arity = #{cnt}
23 #{$indent}}
24 |
25 end
26
27 def make_setter(cnt)
28 underscores = (["_"]*cnt).join(",")
29 head = %Q|\n#{$indent}implicit object Tup#{cnt}Setter extends TupleSetter[Tuple#{cnt}[#{underscores}]] {
30 #{$indent} override def apply(arg : Tuple#{cnt}[#{underscores}]) = {
31 #{$indent} val tup = new Tuple
32 #{$indent} |
33 middle = (1..cnt).map {|c| "tup.add(arg._#{c})" }.join("\n#{$indent} ")
34 tail = %Q|
35 #{$indent} tup
36 #{$indent} }
37
38 #{$indent} override def arity = #{cnt}
39 #{$indent}}|
40 head + middle + tail
41 end
42
43 puts "// following were autogenerated by #{__FILE__} at #{Time.now} do not edit"
44 puts %q|package com.twitter.scalding
45 import cascading.tuple.Tuple
46 import cascading.tuple.TupleEntry
47
48 trait GeneratedConversions extends LowPriorityConversions {
49 |
50
51 (1..22).each { |c|
52 puts make_tuple_conv(c)
53 puts make_setter(c)
54 }
55
56 puts "}"
57 puts "// end of autogenerated"
Something went wrong with that request. Please try again.