Class: RablToJbuilder::ChildTransformer
- Defined in:
- lib/rabl_to_jbuilder/transformer.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from RablToJbuilder::Base
Instance Method Details
#process_iter(exp) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rabl_to_jbuilder/transformer.rb', line 39 def process_iter(exp) exp.shift # :iter call = exp.shift args = exp.shift block = exp.shift if call[0..2] == s(:call, nil, :child) child = call key, attribute = nil, nil if child[3][0] == :lit key = child[3][1] attribute = s(:call, @object, key) elsif child[3][0] == :hash _, attribute, key = child[3] if attribute[0] == :lit attribute = s(:call, @object, attribute[1]) end raise unless key[0] == :lit key = key[1] else raise "wtf" end if plural?(key) singular_key = key.to_s.singularize.to_sym args = s(:args, singular_key) block = Transformer.new(s(:lvar, singular_key)).process(block) s(:iter, s(:call, json, key, attribute), args, block) else args = 0 block = Transformer.new(attribute).process(block) s(:iter, s(:call, json, key), args, block) end elsif call[0..2] == s(:call, nil, :glue) raise unless call[3][0] == :lit attribute = call[3][1] object = s(:call, @object, attribute) block = Transformer.new(object).process(block) block else s(:iter, call, args, block) end end |