Class: Oplogjam::Operators::UnsetIndex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ UnsetIndex

Returns a new instance of UnsetIndex.



6
7
8
# File 'lib/oplogjam/operators/unset_index.rb', line 6

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/oplogjam/operators/unset_index.rb', line 4

def path
  @path
end

Instance Method Details

#delete(column) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/oplogjam/operators/unset_index.rb', line 10

def delete(column)
  nullify_or_unset = Sequel.case(
    [
      [
        column[parent_path].array_length > index,
        column.set(path, NULL)
      ]
    ],
    column.delete_path(path)
  )

  Sequel.pg_jsonb_op(
    Sequel.case(
      { ARRAY_TYPE => nullify_or_unset },
      column.delete_path(path),
      column[parent_path].typeof
    )
  )
end

#indexObject



34
35
36
# File 'lib/oplogjam/operators/unset_index.rb', line 34

def index
  Integer(path.last, 10)
end

#parent_pathObject



30
31
32
# File 'lib/oplogjam/operators/unset_index.rb', line 30

def parent_path
  path[0...-1]
end