Class: Groupdate::Adapters::BaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/groupdate/adapters/base_adapter.rb

Direct Known Subclasses

MySQLAdapter, PostgreSQLAdapter, SQLiteAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:) ⇒ BaseAdapter

Returns a new instance of BaseAdapter.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/groupdate/adapters/base_adapter.rb', line 6

def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:)
  @relation = relation
  @column = column
  @period = period
  @time_zone = time_zone
  @time_range = time_range
  @week_start = week_start
  @day_start = day_start
  @n_seconds = n_seconds

  if ActiveRecord::VERSION::MAJOR >= 7
    if ActiveRecord.default_timezone == :local
      raise Groupdate::Error, "ActiveRecord.default_timezone must be :utc to use Groupdate"
    end
  else
    if relation.default_timezone == :local
      raise Groupdate::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate"
    end
  end
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'lib/groupdate/adapters/base_adapter.rb', line 4

def column
  @column
end

#day_startObject (readonly)

Returns the value of attribute day_start.



4
5
6
# File 'lib/groupdate/adapters/base_adapter.rb', line 4

def day_start
  @day_start
end

#n_secondsObject (readonly)

Returns the value of attribute n_seconds.



4
5
6
# File 'lib/groupdate/adapters/base_adapter.rb', line 4

def n_seconds
  @n_seconds
end

#periodObject (readonly)

Returns the value of attribute period.



4
5
6
# File 'lib/groupdate/adapters/base_adapter.rb', line 4

def period
  @period
end

#week_startObject (readonly)

Returns the value of attribute week_start.



4
5
6
# File 'lib/groupdate/adapters/base_adapter.rb', line 4

def week_start
  @week_start
end

Instance Method Details

#generateObject



27
28
29
# File 'lib/groupdate/adapters/base_adapter.rb', line 27

def generate
  @relation.group(group_clause).where(*where_clause)
end