Closed antulik closed 11 years ago
This is how mongoid 2.0 set attributes
bam = Object.new
def bam.attributes
{bam: "bam", _id: "123", _type: "Bam"}
end
class Bam
include Mongoid::Document
field :bam
field :fam, type: Hash
end
result = Bam.new(bam: bam, fam: bam)
result.bam
# => {"bam" => "bam", "_id" => "123", "_type" => "Bam"}
result.fam
# => #<Object...>
I fathom that this is what is tripping streama load_instance. So if we patch up lib/streama/actor.rb , then should be better.
# Caveat: this is untested
#
# open up Streama::Actor and patch
#
# pristine code is located here lib/streama/actor.rb
module Streama
module Actor
def publish_activity(name, options={})
options[:receivers] = self.send(options[:receivers]) if options[:receivers].is_a?(Symbol)
data = {:actor => {"id" => self.id, "type" => self.class.name}}.merge(options) # explicitly set id and type key
activity = activity_class.publish(name, data)
end
end
end
Streama >= 3.6 requires Mongoid 3. The Gemfile has been updated to require this.
Using mongoid 2.0. Works in steama 0.3.5, but not in 0.3.6.
did some debugging:
error happens here: https://github.com/christospappas/streama/blob/master/lib/streama/activity.rb#L90
type == :actor self.read_attribute(type) returns hash which has '_type' but no 'type' key.
After plain a bit more and reverting that line https://github.com/christospappas/streama/commit/9010eebb8f509567adfb717fbd4e0c0a630ce835#L2R11
to this:
I have only actor but probably other fields will have the same issue.
Everything works after that reverted line. self.read_attribute(type) returns Object but not hash. Can't really explain that behaviour, but hopefully it will give you some ideas where to look.