# File lib/dm-serializer/to_json.rb, line 18 def as_json(options={}) result = {} properties_to_serialize(options).each do |property| property_name = property.name result[property_name] = __send__(property_name) end # add methods Array(options[:methods]).each do |method| next unless respond_to?(method) result[method] = __send__(method) end # Note: if you want to include a whole other model via relation, use :methods # comments.to_json(:relationships=>{:user=>{:include=>[:first_name],:methods=>[:age]}}) # add relationships # TODO: This needs tests and also needs to be ported to #to_xml and #to_yaml (options[:relationships] || {}).each do |relationship_name, opts| next unless respond_to?(relationship_name) result[relationship_name] = __send__(relationship_name).to_json(opts.merge(:to_json => false)) end result end