vendor/gems/gattica-0.6.1/lib/gattica/engine.rb
# Validates that the args passed to +get+ are valid
Validates that the args passed to +get+ are valid
Validates that the args passed to + get + are valid
def validate_and_clean(args)
      raise GatticaError::MissingStartDate, ':start_date is required' if args[:start_date].nil? || args[:start_date].empty?
      raise GatticaError::MissingEndDate, ':end_date is required' if args[:end_date].nil? || args[:end_date].empty?
      raise GatticaError::TooManyDimensions, 'You can only have a maximum of 7 dimensions' if args[:dimensions] && (args[:dimensions].is_a?(Array) && args[:dimensions].length > 7)
      raise GatticaError::TooManyMetrics, 'You can only have a maximum of 10 metrics' if args[:metrics] && (args[:metrics].is_a?(Array) && args[:metrics].length > 10)
      possible = args[:dimensions] + args[:metrics]
      if args[:sort]
        missing = args[:sort].find_all do |arg|
          !possible.include? arg.gsub(/^-/,'')    
        end
        unless missing.empty?
          raise GatticaError::InvalidSort, "You are trying to sort by fields that are not in the available dimensions or metrics: #{missing.join(', ')}"
        end
      end
      if args[:filters]
        missing = args[:filters].find_all do |arg|
          !possible.include? arg.match(/^\w*/).to_s    
        end
        unless missing.empty?
          raise GatticaError::InvalidSort, "You are trying to filter by fields that are not in the available dimensions or metrics: #{missing.join(', ')}"
        end
      end
      return args
    end
def validate_and_clean ( args ) raise GatticaError :: MissingStartDate , ':start_date is required' if args [ :start_date ] . nil? || args [ :start_date ] . empty? raise GatticaError :: MissingEndDate , ':end_date is required' if args [ :end_date ] . nil? || args [ :end_date ] . empty? raise GatticaError :: TooManyDimensions , 'You can only have a maximum of 7 dimensions' if args [ :dimensions ] && ( args [ :dimensions ] . is_a? ( Array ) && args [ :dimensions ] . length > 7 ) raise GatticaError :: TooManyMetrics , 'You can only have a maximum of 10 metrics' if args [ :metrics ] && ( args [ :metrics ] . is_a? ( Array ) && args [ :metrics ] . length > 10 ) possible = args [ :dimensions ] + args [ :metrics ] if args [ :sort ] missing = args [ :sort ] . find_all do | arg | ! possible . include? arg . gsub ( / ^- / , '' ) end unless missing . empty? raise GatticaError :: InvalidSort , "You are trying to sort by fields that are not in the available dimensions or metrics: #{missing.join(', ')}" end end if args [ :filters ] missing = args [ :filters ] . find_all do | arg | ! possible . include? arg . match ( / ^ \w * / ) . to_s end unless missing . empty? raise GatticaError :: InvalidSort , "You are trying to filter by fields that are not in the available dimensions or metrics: #{missing.join(', ')}" end end return args end
Validates that the args passed to +get+ are valid
Validates that the args passed to + get + are valid
# make sure that the user is only trying to sort fields that they've previously included with dimensions and metrics # remove possible minuses from any sort params # make sure that the user is only trying to filter fields that are in dimensions or metrics # get the name of the filter and compare
args
<not_specific>