Module: Promiscuous::Publisher::Model::Mock

Extended by:
ActiveSupport::Concern
Includes:
Ephemeral
Defined in:
lib/promiscuous/publisher/model/mock.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Ephemeral

#destroyed, #id, #new_record

Instance Method Summary collapse

Methods included from Ephemeral

#attributes, #destroy, #save, #update_attributes

Methods included from Base

#promiscuous, #valid?

Instance Method Details

#__get_new_idObject



15
16
17
18
19
20
21
22
23
# File 'lib/promiscuous/publisher/model/mock.rb', line 15

def __get_new_id
  if self.class.mock_options[:id] == :bson
    BSON::ObjectId.new
  else
    # XXX Not thread safe
    @@next_id ||= 1
    @@next_id += 1
  end
end

#initialize(attrs = {}) ⇒ Object



10
11
12
13
# File 'lib/promiscuous/publisher/model/mock.rb', line 10

def initialize(attrs={})
  self.id = __get_new_id
  super
end

#save_operation(operation) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/promiscuous/publisher/model/mock.rb', line 25

def save_operation(operation)
  payload = nil

  op = Promiscuous::Publisher::Operation::Ephemeral.new(:instance => self, :operation => operation)
  # TODO FIX the mocks to populate app name, also we need to hook before the
  # json dump.
  payload = op.generate_payload

  Promiscuous::Subscriber::Message.new(payload).process
end