Class: Druid::Query::GranularityValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/druid/query.rb

Constant Summary collapse

TYPES =
%w(timeseries search groupBy select topN)
SIMPLE =
%w(all none minute fifteen_minute thirty_minute hour day)

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/druid/query.rb', line 49

def validate_each(record, attribute, value)
  if TYPES.include?(record.queryType)
    if value.is_a?(String)
      record.errors.add(attribute, "must be one of #{SIMPLE.inspect}") unless SIMPLE.include?(value)
    elsif value.is_a?(Granularity)
      value.valid? # trigger validation
      value.errors.messages.each do |k, v|
        record.errors.add(attribute, { k => v })
      end
    else
      record.errors.add(attribute, "invalid type or class: #{value.inspect}")
    end
  else
    record.errors.add(attribute, "is not supported by type=#{record.queryType}") if value
  end
end