Class: Groupdate::RelationBuilder
- Inherits:
-
Object
- Object
- Groupdate::RelationBuilder
- Includes:
- SqlServerGroupClause
- Defined in:
- lib/groupdate/relation_builder.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#day_start ⇒ Object
readonly
Returns the value of attribute day_start.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#series_label ⇒ Object
readonly
Returns the value of attribute series_label.
-
#week_start ⇒ Object
readonly
Returns the value of attribute week_start.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, series_label:) ⇒ RelationBuilder
constructor
A new instance of RelationBuilder.
Methods included from SqlServerGroupClause
Constructor Details
#initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, series_label:) ⇒ RelationBuilder
Returns a new instance of RelationBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/groupdate/relation_builder.rb', line 8 def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, series_label:) @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 @series_label = series_label if relation.default_timezone == :local raise Groupdate::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate" end end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
6 7 8 |
# File 'lib/groupdate/relation_builder.rb', line 6 def column @column end |
#day_start ⇒ Object (readonly)
Returns the value of attribute day_start.
6 7 8 |
# File 'lib/groupdate/relation_builder.rb', line 6 def day_start @day_start end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
6 7 8 |
# File 'lib/groupdate/relation_builder.rb', line 6 def period @period end |
#series_label ⇒ Object (readonly)
Returns the value of attribute series_label.
6 7 8 |
# File 'lib/groupdate/relation_builder.rb', line 6 def series_label @series_label end |
#week_start ⇒ Object (readonly)
Returns the value of attribute week_start.
6 7 8 |
# File 'lib/groupdate/relation_builder.rb', line 6 def week_start @week_start end |
Instance Method Details
#generate ⇒ Object
23 24 25 26 27 28 |
# File 'lib/groupdate/relation_builder.rb', line 23 def generate group_by = group_clause @relation = @relation.group(group_by).where(*where_clause) @relation.select_values += ["#{group_by} AS #{series_label}"] if series_label @relation end |