Class: Groupdate::RelationBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RelationBuilder.


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/groupdate/relation_builder.rb', line 5

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

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

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column


3
4
5
# File 'lib/groupdate/relation_builder.rb', line 3

def column
  @column
end

#day_startObject (readonly)

Returns the value of attribute day_start


3
4
5
# File 'lib/groupdate/relation_builder.rb', line 3

def day_start
  @day_start
end

#periodObject (readonly)

Returns the value of attribute period


3
4
5
# File 'lib/groupdate/relation_builder.rb', line 3

def period
  @period
end

#week_startObject (readonly)

Returns the value of attribute week_start


3
4
5
# File 'lib/groupdate/relation_builder.rb', line 3

def week_start
  @week_start
end

Instance Method Details

#generateObject


19
20
21
# File 'lib/groupdate/relation_builder.rb', line 19

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