Class: Oplogjam::Operators::Unset

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unsets = []) ⇒ Unset

Returns a new instance of Unset.



21
22
23
# File 'lib/oplogjam/operators/unset.rb', line 21

def initialize(unsets = [])
  @unsets = unsets
end

Instance Attribute Details

#unsetsObject (readonly)

Returns the value of attribute unsets.



19
20
21
# File 'lib/oplogjam/operators/unset.rb', line 19

def unsets
  @unsets
end

Class Method Details

.from(operation) ⇒ Object



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

def self.from(operation)
  operation.each_with_object(new) do |(dotted_path, _), unset|
    path = dotted_path.split(FIELD_SEPARATOR)

    if path.last =~ NUMERIC_INDEX
      unset.unset_index(path)
    else
      unset.unset_field(path)
    end
  end
end

Instance Method Details

#delete(column) ⇒ Object



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

def delete(column)
  unsets.inject(column) do |subject, unset|
    unset.delete(subject)
  end
end

#unset_field(path) ⇒ Object



25
26
27
# File 'lib/oplogjam/operators/unset.rb', line 25

def unset_field(path)
  unsets << UnsetField.new(path)
end

#unset_index(path) ⇒ Object



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

def unset_index(path)
  unsets << UnsetIndex.new(path)
end