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:, n_seconds:) ⇒ RelationBuilder

Returns a new instance of RelationBuilder.



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

def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:)
  # very important
  validate_column(column)

  @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
  @n_seconds = n_seconds

  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

#n_secondsObject (readonly)

Returns the value of attribute n_seconds.



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

def n_seconds
  @n_seconds
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



23
24
25
# File 'lib/groupdate/relation_builder.rb', line 23

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