Class: JSON2Ruby::RubyWriter
- Inherits:
-
Object
- Object
- JSON2Ruby::RubyWriter
- Defined in:
- lib/json2ruby/ruby_writer.rb
Class Method Summary collapse
- .attributes_to_ruby(entity, indent, options = {}) ⇒ Object
- .to_code(entity, indent = 0, options = {}) ⇒ Object
Class Method Details
.attributes_to_ruby(entity, indent, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/json2ruby/ruby_writer.rb', line 30 def self.attributes_to_ruby(entity, indent, = {}) ident = (' '*indent) x = "" entity.attributes.each do |k,v| if (v.is_a?(Collection)) x += "#{ident}#{options[:collectionmethod]} :#{k}" else x += "#{ident}#{options[:attributemethod]} :#{k}" end if [:includetypes] unless v.is_a?(Primitive) name = ![:namespace].nil? && [:namespace]!="" ? ([:namespace]+"::"+v.name) : v.name x += ", '#{name}'" end end x += " # #{v.comment}\r\n" end x end |
.to_code(entity, indent = 0, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/json2ruby/ruby_writer.rb', line 7 def self.to_code(entity, indent = 0, = {}) x = "" if .has_key?(:require) [:require].each { |r| x += "require '#{r}'\r\n" } x += "\r\n" end idt = (' '*indent) x += "#{(' '*indent)}#{options[:modules] ? "module" : "class"} #{entity.name}" x += " < #{options[:superclass_name]}" if .has_key?(:superclass_name) x += "\r\n" if .has_key?(:extend) [:extend].each { |r| x += "#{(' '*(indent+2))}extend #{r}\r\n" } x += "\r\n" end if .has_key?(:include) [:include].each { |r| x += "#{(' '*(indent+2))}include #{r}\r\n" } x += "\r\n" end x += attributes_to_ruby(entity, indent+2, ) x += "#{(' '*indent)}end\r\n" x end |