Class: SlidingPartition::TableCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/sliding_partition/table_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition:, at_time:) ⇒ TableCollection

Returns a new instance of TableCollection.



14
15
16
# File 'lib/sliding_partition/table_collection.rb', line 14

def initialize(definition:, at_time:)
  @definition, @time = definition, at_time
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



9
10
11
# File 'lib/sliding_partition/table_collection.rb', line 9

def definition
  @definition
end

#timeObject (readonly)

Returns the value of attribute time.



9
10
11
# File 'lib/sliding_partition/table_collection.rb', line 9

def time
  @time
end

Instance Method Details

#each(&block) ⇒ Object



26
27
28
# File 'lib/sliding_partition/table_collection.rb', line 26

def each(&block)
  tables.each(&block)
end

#earliest_record_timestampObject



46
47
48
# File 'lib/sliding_partition/table_collection.rb', line 46

def earliest_record_timestamp
  definition.model.order("#{time_column} ASC").limit(1).first[time_column]
end

#first_partition_timestampObject



42
43
44
# File 'lib/sliding_partition/table_collection.rb', line 42

def first_partition_timestamp
  tables.first.timestamp_floor
end

#first_timestampObject



30
31
32
33
34
35
36
# File 'lib/sliding_partition/table_collection.rb', line 30

def first_timestamp
  @first_timestamp ||= if retention_interval == :forever
                         earliest_record_timestamp
                       else
                         time - retention_interval
                       end
end

#last_timestampObject



38
39
40
# File 'lib/sliding_partition/table_collection.rb', line 38

def last_timestamp
  time + lead_time + partition_interval
end

#tablesObject



18
19
20
21
22
23
24
# File 'lib/sliding_partition/table_collection.rb', line 18

def tables
  @tables ||= begin
    (first_timestamp.to_i...last_timestamp.to_i).step(partition_interval).map do |partition_time|
      PartitionTable.new(for_time: Time.at(partition_time), definition: definition)
    end
  end
end