Class: Perpetuity::Postgres::IndexCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/perpetuity/postgres/index_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, *indexes) ⇒ IndexCollection

Returns a new instance of IndexCollection.



10
11
12
13
# File 'lib/perpetuity/postgres/index_collection.rb', line 10

def initialize table, *indexes
  @table = table.to_s
  @indexes = indexes.flatten.to_set
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



8
9
10
# File 'lib/perpetuity/postgres/index_collection.rb', line 8

def table
  @table
end

Instance Method Details

#-(other) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/perpetuity/postgres/index_collection.rb', line 35

def - other
  difference = self.class.new(table)
  each do |index|
    unless other.include? index
      difference << index
    end
  end

  difference
end

#<<(index) ⇒ Object



15
16
17
# File 'lib/perpetuity/postgres/index_collection.rb', line 15

def << index
  @indexes << index
end

#==(other) ⇒ Object



46
47
48
49
50
# File 'lib/perpetuity/postgres/index_collection.rb', line 46

def == other
  table == other.table &&
  count == other.count &&
  (self - other).empty?
end

#eachObject



19
20
21
# File 'lib/perpetuity/postgres/index_collection.rb', line 19

def each
  @indexes.each { |index| yield index }
end

#reject!(&block) ⇒ Object



23
24
25
# File 'lib/perpetuity/postgres/index_collection.rb', line 23

def reject! &block
  @indexes.reject!(&block)
end

#to_aObject



27
28
29
# File 'lib/perpetuity/postgres/index_collection.rb', line 27

def to_a
  @indexes.to_a
end

#to_aryObject



31
32
33
# File 'lib/perpetuity/postgres/index_collection.rb', line 31

def to_ary
  to_a
end