Class: Oplogjam::ApplyOps

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, ts, ns, apply_ops) ⇒ ApplyOps

Returns a new instance of ApplyOps.



19
20
21
22
23
24
# File 'lib/oplogjam/apply_ops.rb', line 19

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

Instance Attribute Details

#apply_opsObject (readonly)

Returns the value of attribute apply_ops.



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

def apply_ops
  @apply_ops
end

#hObject (readonly) Also known as: id

Returns the value of attribute h.



5
6
7
# File 'lib/oplogjam/apply_ops.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/apply_ops.rb', line 5

def ns
  @ns
end

#tsObject (readonly)

Returns the value of attribute ts.



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

def ts
  @ts
end

Class Method Details

.from(bson) ⇒ Object



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

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

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

Instance Method Details

#==(other) ⇒ Object



43
44
45
46
47
# File 'lib/oplogjam/apply_ops.rb', line 43

def ==(other)
  return unless other.is_a?(ApplyOps)

  id == other.id
end

#apply(mapping) ⇒ Object



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

def apply(mapping)
  operations.each do |operation|
    operation.apply(mapping)
  end
end

#operationsObject



39
40
41
# File 'lib/oplogjam/apply_ops.rb', line 39

def operations
  apply_ops.map { |bson| Operation.from(bson) }
end

#timestampObject



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

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