Class: Oplogjam::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/oplogjam/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, ts, ns, o) ⇒ Command

Returns a new instance of Command.



18
19
20
21
22
23
# File 'lib/oplogjam/command.rb', line 18

def initialize(h, ts, ns, o)
  @h = Integer(h)
  @ts = Oplogjam::Timestamp(ts)
  @ns = String(ns)
  @o = Oplogjam::Document(o)
end

Instance Attribute Details

#hObject (readonly) Also known as: id

Returns the value of attribute h.



5
6
7
# File 'lib/oplogjam/command.rb', line 5

def h
  @h
end

#nsObject (readonly) Also known as: namespace

Returns the value of attribute ns.



5
6
7
# File 'lib/oplogjam/command.rb', line 5

def ns
  @ns
end

#oObject (readonly) Also known as: command

Returns the value of attribute o.



5
6
7
# File 'lib/oplogjam/command.rb', line 5

def o
  @o
end

#tsObject (readonly)

Returns the value of attribute ts.



5
6
7
# File 'lib/oplogjam/command.rb', line 5

def ts
  @ts
end

Class Method Details

.from(bson) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/oplogjam/command.rb', line 7

def self.from(bson)
  h = bson.fetch(H)
  ts = bson.fetch(TS)
  ns = bson.fetch(NS)
  o = bson.fetch(O)

  new(h, ts, ns, o)
rescue KeyError => e
  raise InvalidCommand, "missing field: #{e}"
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
# File 'lib/oplogjam/command.rb', line 33

def ==(other)
  return false unless other.is_a?(Command)

  id == other.id
end

#apply(_mapping) ⇒ Object



39
# File 'lib/oplogjam/command.rb', line 39

def apply(_mapping); end

#timestampObject



29
30
31
# File 'lib/oplogjam/command.rb', line 29

def timestamp
  Time.at(ts.seconds, ts.increment)
end