Class: Dbwatcher::Storage::QueryValidator
- Inherits:
-
Object
- Object
- Dbwatcher::Storage::QueryValidator
- Defined in:
- lib/dbwatcher/storage/query_validator.rb
Constant Summary collapse
- REQUIRED_FIELDS =
[:timestamp].freeze
Class Method Summary collapse
Class Method Details
.valid?(query) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/dbwatcher/storage/query_validator.rb', line 8 def self.valid?(query) return false unless query.is_a?(Hash) REQUIRED_FIELDS.all? { |field| query.key?(field) && !query[field].nil? } end |
.validate!(query) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/dbwatcher/storage/query_validator.rb', line 14 def self.validate!(query) raise ArgumentError, "Query must be a Hash" unless query.is_a?(Hash) missing_fields = REQUIRED_FIELDS.reject { |field| query.key?(field) } return true if missing_fields.empty? raise ArgumentError, "Missing required fields: #{missing_fields.join(", ")}" end |