require "peto/mixin/peto_class" <%- name = @target[:name].camelize -%> <%- args = @target[:args] -%> module Peto class <%= name %> include PetoClass def self.create(hash_args) instance = new <%- args.each do |arg| -%> <%- if atomic_types.include?(arg[:type].constantize) -%> instance.<%=arg[:name]%> = hash_args["<%= arg[:name]%>"] <%- elsif arg[:array_type] -%> instance.<%=arg[:name]%> = hash_args["<%= arg[:name]%>"].map {|arg| <%=arg[:array_type]%>.create(arg) } <%- else -%> instance.<%=arg[:name]%> = <%=arg[:type]%>.create(hash_args["<%= arg[:name]%>"]) <%- end -%> <%- end -%> return instance end def initialize(args={}) <%- args.each do |arg| -%> <%- if arg[:array_type] -%> @<%= arg[:name] %> = [] # for <%= arg[:array_type] %> <%- else -%> @<%= arg[:name] %> = nil <%- end -%> <%- end -%> set_args(args) raise_errors unless valid? end <%- args.each do |arg| -%> attr_reader :<%= arg[:name] %> <%- end -%> <%- args.each do |arg| -%> def <%= arg[:name] %>=(value) @<%=arg[:name]%> = value raise_errors unless valid? end <%- end -%> def members [<%= args.map{|arg| ":#{arg[:name]}"}.join(",") %>] end def types {<%= args.map{|arg| ":#{arg[:name]} => #{arg[:type]}"}.join(",") %>} end def arrays {<%= args.select{|arg|arg[:array_type]}.map{|arg| ":#{arg[:name]} => #{arg[:array_type]}"}.join(",") %>} end end end