Module: Mongoid::Document
- Included in:
- ActivityNotification::ORM::Mongoid::Notification, ActivityNotification::ORM::Mongoid::Subscription
- Defined in:
- lib/activity_notification/orm/mongoid.rb
Overview
Monkey patching for Mongoid::Document as_json
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Hash
Monkey patching for Mongoid::Document as_json.
Instance Method Details
#as_json(options = {}) ⇒ Hash
Monkey patching for Mongoid::Document as_json
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/activity_notification/orm/mongoid.rb', line 89 def as_json( = {}) json = super() json["id"] = json["_id"].to_s.start_with?("{\"$oid\"=>") ? self.id.to_s : json["_id"].to_s if .has_key?(:include) case [:include] when Symbol then json[[:include].to_s] = self.send([:include]).as_json when Array then [:include].each {|model| json[model.to_s] = self.send(model).as_json } when Hash then [:include].each {|model, | json[model.to_s] = self.send(model).as_json() } end end json end |