Sha256: 2ad2509196d44148197737eb92d3e53e74a50b9c40c7ddafee3c38dbf9491316

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

# dependencies
require "active_support"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/time"

# modules
require "groupdate/magic"
require "groupdate/series_builder"
require "groupdate/version"

# adapters
require "groupdate/adapters/base_adapter"
require "groupdate/adapters/mysql_adapter"
require "groupdate/adapters/postgresql_adapter"
require "groupdate/adapters/redshift_adapter"
require "groupdate/adapters/sqlite_adapter"

module Groupdate
  class Error < RuntimeError; end

  PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :minute_of_hour, :day_of_month, :day_of_year, :month_of_year]
  METHODS = PERIODS.map { |v| :"group_by_#{v}" } + [:group_by_period]

  mattr_accessor :week_start, :day_start, :time_zone, :dates
  self.week_start = :sunday
  self.day_start = 0
  self.dates = true

  # api for gems like ActiveMedian
  def self.process_result(relation, result, **options)
    if relation.groupdate_values
      result = Groupdate::Magic::Relation.process_result(relation, result, **options)
    end
    result
  end

  def self.adapters
    @adapters ||= {}
  end

  def self.register_adapter(name, adapter)
    Array(name).each do |n|
      adapters[n] = adapter
    end
  end
end

Groupdate.register_adapter ["Mysql2", "Mysql2Spatial", "Mysql2Rgeo"], Groupdate::Adapters::MySQLAdapter
Groupdate.register_adapter ["PostgreSQL", "PostGIS"], Groupdate::Adapters::PostgreSQLAdapter
Groupdate.register_adapter "Redshift", Groupdate::Adapters::RedshiftAdapter
Groupdate.register_adapter "SQLite", Groupdate::Adapters::SQLiteAdapter

require "groupdate/enumerable"

ActiveSupport.on_load(:active_record) do
  require "groupdate/active_record"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
groupdate-5.2.4 lib/groupdate.rb
groupdate-5.2.3 lib/groupdate.rb