require "peto/mixin/peto_errorable" module Peto class Foo extend PetoErrorable # set_user methods def self.set_user(user) set_user_valid?(user) return { :procedure => "set_user", :args => { :user => hashize(user), } } end def self.set_user_valid?(user) invalid_type("user", User, user) unless user.class == User raise_errors unless errors.empty? end def self.set_user_hash_to_args(hash_args) args = [] args.push(User.create(hash_args["user"])) return args end # set_user_response methods def self.set_user_response(a,b) set_user_response_valid?(a,b) return { :procedure => "set_user_response", :args => { :a => hashize(a), :b => hashize(b), } } end def self.set_user_response_valid?(a,b) invalid_type("a", Fixnum, a) unless a.class == Fixnum invalid_type("b", String, b) unless b.class == String raise_errors unless errors.empty? end def self.set_user_response_hash_to_args(hash_args) args = [] args.push(Fixnum.create(hash_args["a"])) args.push(String.create(hash_args["b"])) return args end # set_user_error_invalid_user methods def self.set_user_error_invalid_user(message) set_user_error_invalid_user_valid?(message) return { :procedure => "set_user_error_invalid_user", :args => { :message => hashize(message), } } end def self.set_user_error_invalid_user_valid?(message) invalid_type("message", String, message) unless message.class == String raise_errors unless errors.empty? end def self.set_user_error_invalid_user_hash_to_args(hash_args) args = [] args.push(String.create(hash_args["message"])) return args end def self.hashize(var) return var if primitive_type?(var.class) var.to_hash end def self.primitive_type?(type) [Fixnum,String].include?(type) end end end