Changeset 9202 for trunk/activerecord/lib/active_record/serializers
- Timestamp:
- 04/01/08 20:09:45 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/serializers/json_serializer.rb
r9093 r9202 1 1 module ActiveRecord #:nodoc: 2 2 module Serialization 3 def self.included(base) 4 base.cattr_accessor :include_root_in_json, :instance_writer => false 5 base.extend ClassMethods 6 end 7 3 8 # Returns a JSON string representing the model. Some configuration is 4 9 # available through +options+. … … 49 54 # "title": "So I was thinking"}]} 50 55 def to_json(options = {}) 51 JsonSerializer.new(self, options).to_s 56 if include_root_in_json 57 "{#{self.class.json_class_name}: #{JsonSerializer.new(self, options).to_s}}" 58 else 59 JsonSerializer.new(self, options).to_s 60 end 52 61 end 53 62 … … 62 71 end 63 72 end 73 74 module ClassMethods 75 def json_class_name 76 @json_class_name ||= name.demodulize.underscore.inspect 77 end 78 end 64 79 end 65 80 end