Sha256: be524c19e2f1ed1da27c65a1cd70ec832c179985bf6d5028ee24a453e509ead3

Contents?: true

Size: 844 Bytes

Versions: 3

Compression:

Stored size: 844 Bytes

Contents

module Partitioned
  #
  # Partition tables by a time field grouping them by day, with
  # a day defined as 24 hours.
  #
  class ByDailyTimeField < ByTimeField
    self.abstract_class = true

    #
    # Normalize a partition key value by day.
    #
    # @param [Time] time_value the time value to normalize
    # @return [Time] the value normalized
    def self.partition_normalize_key_value(time_value)
      return time_value.at_beginning_of_day.to_date
    end

    #
    # The size of the partition table, 1 day (24 hours)
    # 
    # @return [Integer] the size of this partition
    def self.partition_table_size
      return 1.day
    end

    partitioned do |partition|
      partition.base_name lambda { |model, time_field|
        return model.partition_normalize_key_value(time_field).strftime('%Y%m%d')
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
partitioned-2.1.0 lib/partitioned/by_daily_time_field.rb
partitioned-2.0.0 lib/partitioned/by_daily_time_field.rb
partitioned-1.3.5 lib/partitioned/by_daily_time_field.rb