module ActiveSupport::CoreExtensions::Array::Conversions

refer to: api.rubyonrails.org/ for more details

Public Instance Methods

to_amf(options = {}) click to toggle source

Serialize as AMF

# File lib/restfulx/rx_active_support.rb, line 120
 def to_amf(options = {})
   raise "Not all elements respond to to_amf" unless all? { |e| e.respond_to? :to_amf }
   
   options[:attributes] ||= {}
   options[:serializer] ||= RestfulX::AMF::RxAMFSerializer.new
   options[:serializer].serialize_typed_array(self, options).to_s
end
to_fxml(options = {}) { |xml| ... } click to toggle source

Flex friendly XML format (no dashes, etc)

# File lib/restfulx/rx_active_support.rb, line 85
def to_fxml(options = {})
  raise "Not all elements respond to to_fxml" unless all? { |e| e.respond_to? :to_fxml }

  options[:root]     ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
  options[:children] ||= options[:root].singularize
  options[:indent]   ||= 2
  options[:builder]  ||= Builder::XmlMarkup.new(:indent => options[:indent])
  options.merge!(:dasherize => false)
  
  options[:attributes] ||= {}
  options[:attributes].merge!(:type => "array")

  root     = options.delete(:root).to_s
  children = options.delete(:children)

  if !options.has_key?(:dasherize) || options[:dasherize]
    root = root.dasherize
  end

  options[:builder].instruct! unless options.delete(:skip_instruct)

  opts = options.merge({ :root => children })

  xml = options[:builder]
  if empty?
    xml.tag!(root, options[:attributes])
  else
    xml.tag!(root, options[:attributes]) {
      yield xml if block_given?
      each { |e| e.to_fxml(opts.merge!({ :skip_instruct => true })) }
    }
  end
end