Module: ActiveCollection::Serialization
- Defined in:
- lib/active_collection/serialization.rb
Instance Method Summary collapse
- #as_data_hash ⇒ Object
- #as_json(options = nil) ⇒ Object
-
#to_param ⇒ Object
Turn the params into a hash suitable such that passing the collection directly to a named path generates the path for the current collection.
- #to_xml(options = {}) ⇒ Object
Instance Method Details
#as_data_hash ⇒ Object
9 10 11 12 13 |
# File 'lib/active_collection/serialization.rb', line 9 def as_data_hash data_hash = { table_name => collection.as_json } data_hash["total_entries"] = total_entries data_hash end |
#as_json(options = nil) ⇒ Object
30 31 32 |
# File 'lib/active_collection/serialization.rb', line 30 def as_json( = nil) {"collection" => as_data_hash}.as_json() end |
#to_param ⇒ Object
Turn the params into a hash suitable such that passing the collection directly to a named path generates the path for the current collection.
5 6 7 |
# File 'lib/active_collection/serialization.rb', line 5 def to_param params.empty?? nil : params.to_param end |
#to_xml(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_collection/serialization.rb', line 15 def to_xml( = {}) collect [:indent] ||= 2 xml = [:builder] ||= Builder::XmlMarkup.new(:indent => [:indent]) xml.instruct! unless [:skip_instruct] xml.collection do xml.total_entries(total_entries, :type => "integer") xml.tag!(table_name, :type => "array") do collection.each do |item| item.to_xml(:indent => [:indent], :builder => xml, :skip_instruct => true) end end end end |