Module: XiWechatCorp::Callback::Grape::Formatter

Defined in:
lib/xi_wechat_corp/callback/grape.rb

Overview

Set this as the default XML formater in Grape

formatter :xml, XiWechatCorp::Callback::Grape::Formatter

Class Method Summary collapse

Class Method Details

.call(object, env) ⇒ Object



21
22
23
24
25
26
# File 'lib/xi_wechat_corp/callback/grape.rb', line 21

def self.call(object, env)
  return object if object.is_a?(String)
  return '' if object.nil?
  return object.to_xml(root: 'xml', skip_instruct: true, indent: 0) if object.respond_to?(:to_xml)
  fail ::Grape::Exceptions::InvalidFormatter.new(object.class, 'xml')
end