Class: Promiscuous::Publisher::Model::Mongoid::PromiscuousMethods

Inherits:
Object
  • Object
show all
Includes:
Base::PromiscuousMethodsBase
Defined in:
lib/promiscuous/publisher/model/mongoid.rb

Instance Method Summary collapse

Methods included from Base::PromiscuousMethodsBase

#attributes, #get_dependency, #id, #initialize, #payload

Instance Method Details

#attribute(attr) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/promiscuous/publisher/model/mongoid.rb', line 31

def attribute(attr)
  value = super
  if value.is_a?(Array) &&
     value.respond_to?(:ancestors) &&
     value.ancestors.any? { |a| a == Promiscuous::Publisher::Model::Mongoid }
    value = {:types => ['Promiscuous::EmbeddedDocs'],
             :attributes => value.map(&:promiscuous).map(&:payload)}
  end
  value
end

#sync(options = {}, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/promiscuous/publisher/model/mongoid.rb', line 24

def sync(options={}, &block)
  raise "Use promiscuous.sync on the parent instance" if @instance.embedded?

  # We can use the ephemeral because both are mongoid and ephemerals are atomic operations.
  Promiscuous::Publisher::Operation::Ephemeral.new(:instance => @instance, :operation => :update).execute
end