Sha256: 7805fd5fd9f90d485774cfbf239446ffb19e0767c4af83eadda4cee88d143451
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module Aggrobot module QueryPlanner module ParametersValidator def validate_and_extract_relation(collection) if !collection.is_a?(ActiveRecord::Relation) && (collection < ActiveRecord::Base rescue false) collection.unscoped elsif collection.is_a?(ActiveRecord::Relation) collection else raise ArgumentError.new 'Only ActiveRecord Models and Relations can be used in Aggrobot' end end def validate_options(opts, required_parameters, optional_parameters) params = opts.keys # raise errors for required parameters raise_opts_error(opts, required_parameters, optional_parameters) unless (required_parameters - params).empty? # raise errors if any extra arguments given raise_opts_error(opts, required_parameters, optional_parameters) unless (params - required_parameters - optional_parameters).empty? end private def raise_opts_error(opts, required_parameters, optional_parameters) raise ArgumentError, <<-ERR Wrong arguments given - #{opts} Required parameters are #{required_parameters} Optional parameters are #{optional_parameters} ERR end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aggrobot-0.1.0 | lib/aggrobot/query_planner/parameters_validator.rb |