Class: Oplogjam::Delete
- Inherits:
-
Object
- Object
- Oplogjam::Delete
- Defined in:
- lib/oplogjam/delete.rb
Instance Attribute Summary collapse
-
#h ⇒ Object
(also: #id)
readonly
Returns the value of attribute h.
-
#ns ⇒ Object
(also: #namespace)
readonly
Returns the value of attribute ns.
-
#o ⇒ Object
(also: #query)
readonly
Returns the value of attribute o.
-
#ts ⇒ Object
readonly
Returns the value of attribute ts.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply(mapping) ⇒ Object
-
#initialize(h, ts, ns, o) ⇒ Delete
constructor
A new instance of Delete.
- #timestamp ⇒ Object
Constructor Details
Instance Attribute Details
#h ⇒ Object (readonly) Also known as: id
Returns the value of attribute h.
5 6 7 |
# File 'lib/oplogjam/delete.rb', line 5 def h @h end |
#ns ⇒ Object (readonly) Also known as: namespace
Returns the value of attribute ns.
5 6 7 |
# File 'lib/oplogjam/delete.rb', line 5 def ns @ns end |
#o ⇒ Object (readonly) Also known as: query
Returns the value of attribute o.
5 6 7 |
# File 'lib/oplogjam/delete.rb', line 5 def o @o end |
#ts ⇒ Object (readonly)
Returns the value of attribute ts.
5 6 7 |
# File 'lib/oplogjam/delete.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/delete.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 InvalidDelete, "missing field: #{e}" end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 37 |
# File 'lib/oplogjam/delete.rb', line 33 def ==(other) return false unless other.is_a?(Delete) id == other.id end |
#apply(mapping) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/oplogjam/delete.rb', line 39 def apply(mapping) table = mapping[namespace] return unless table row_id = query.fetch(ID).to_json table .where(id: row_id, deleted_at: nil) .update(updated_at: Time.now.utc, deleted_at: Time.now.utc) end |
#timestamp ⇒ Object
29 30 31 |
# File 'lib/oplogjam/delete.rb', line 29 def Time.at(ts.seconds, ts.increment) end |