require "peto/mixin/peto_errorable" <%- def comma_args(args) args.map{|arg| arg[:name]}.join(",") end -%> module Peto class <%= class_name %> extend PetoErrorable <%- each_procedures do |name, args| -%> # <%=name%> methods def self.<%= name %>(<%= comma_args(args) %>) <%=name%>_valid?(<%= comma_args(args) %>) return { :procedure => "<%=name%>", :args => { <%- args.each do |arg| -%> :<%=arg[:name]%> => hashize(<%=arg[:name]%>), <%- end -%> } } end def self.<%=name%>_valid?(<%= comma_args(args) %>) <%- args.each do |arg| -%> invalid_type("<%= arg[:name] %>", <%= arg[:type] %>, <%= arg[:name] %>) unless <%= arg[:name] %>.class == <%= arg[:type] %> <%- end -%> raise_errors unless errors.empty? end def self.<%=name%>_hash_to_args(hash_args) args = [] <%- args.each do |arg| -%> args.push(<%=arg[:type]%>.create(hash_args["<%=arg[:name]%>"])) <%- end -%> return args end <%- end -%> def self.hashize(var) return var if primitive_type?(var.class) var.to_hash end def self.primitive_type?(type) [<%=rb_primitive_types.join(",")%>].include?(type) end end end