Commit a0ed30caf0434e2afa407653681159eaccb06da6
1 parent
c3fff138
Exists in
master
and in
3 other branches
Raise Groupdate errors
Showing
2 changed files
with
6 additions
and
6 deletions
Show diff stats
lib/groupdate.rb
... | ... | @@ -4,7 +4,7 @@ require "groupdate/version" |
4 | 4 | require "groupdate/magic" |
5 | 5 | |
6 | 6 | module Groupdate |
7 | - class Error < StandardError; end | |
7 | + class Error < RuntimeError; end | |
8 | 8 | |
9 | 9 | PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :day_of_month, :month_of_year] |
10 | 10 | # backwards compatibility for anyone who happened to use it | ... | ... |
lib/groupdate/magic.rb
... | ... | @@ -8,9 +8,9 @@ module Groupdate |
8 | 8 | @field = field |
9 | 9 | @options = options |
10 | 10 | |
11 | - raise "Unrecognized time zone" unless time_zone | |
11 | + raise Groupdate::Error, "Unrecognized time zone" unless time_zone | |
12 | 12 | |
13 | - raise "Unrecognized :week_start option" if field == :week && !week_start | |
13 | + raise Groupdate::Error, "Unrecognized :week_start option" if field == :week && !week_start | |
14 | 14 | end |
15 | 15 | |
16 | 16 | def group_by(enum, &_block) |
... | ... | @@ -20,7 +20,7 @@ module Groupdate |
20 | 20 | |
21 | 21 | def relation(column, relation) |
22 | 22 | if relation.default_timezone == :local |
23 | - raise "ActiveRecord::Base.default_timezone must be :utc to use Groupdate" | |
23 | + raise Groupdate::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate" | |
24 | 24 | end |
25 | 25 | |
26 | 26 | time_zone = self.time_zone.tzinfo.name |
... | ... | @@ -97,7 +97,7 @@ module Groupdate |
97 | 97 | ["CONVERT_TIMEZONE(?, 'Etc/UTC', DATE_TRUNC(?, CONVERT_TIMEZONE(?, #{column}) - INTERVAL '#{day_start} second'))::timestamp + INTERVAL '#{day_start} second'", time_zone, field, time_zone] |
98 | 98 | end |
99 | 99 | else |
100 | - raise "Connection adapter not supported: #{adapter_name}" | |
100 | + raise Groupdate::Error, "Connection adapter not supported: #{adapter_name}" | |
101 | 101 | end |
102 | 102 | |
103 | 103 | if adapter_name == "MySQL" && field == :week |
... | ... | @@ -349,7 +349,7 @@ module Groupdate |
349 | 349 | when :month_of_year |
350 | 350 | time.month |
351 | 351 | else |
352 | - raise "Invalid field" | |
352 | + raise Groupdate::Error, "Invalid field" | |
353 | 353 | end |
354 | 354 | |
355 | 355 | time.is_a?(Time) ? time + day_start.seconds : time | ... | ... |