Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/json_serializer/rails/active_record_patch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.serializeObject



7
8
9
# File 'lib/json_serializer/rails/active_record_patch.rb', line 7

def self.serialize
  self.collect{|model| model.send((model.respond_to? :api_attributes) ? :api_attributes : :to_json).merge({:_class_name => self.first.class.name.downcase.pluralize})}.group_by{|d| d[:_class_name] }
end

Instance Method Details

#serializeObject



3
4
5
# File 'lib/json_serializer/rails/active_record_patch.rb', line 3

def serialize
  {"#{self.class.name.downcase.underscore}" => self.send((self.respond_to? :api_attributes) ? :api_attributes : :to_json)}
end