module ActiveEndpoint::Extentions::ActiveRecord

Constants

METHODS

Public Instance Methods

tagged_as(tag, tags = ActiveEndpoint.tags.definition) click to toggle source
# File lib/active_endpoint/extentions/active_record.rb, line 12
def tagged_as(tag, tags = ActiveEndpoint.tags.definition)
  return [] unless tags.keys.include?(tag)

  time_operators = tags[tag]
  last_operator_index = time_operators.keys.length - 1

  query = ''
  time_operators.each_with_index do |(key, value), index|
    operator = METHODS[key]
    duration = (value.to_f / 1000).to_s
    and_operator = last_operator_index == index ? '' : ' AND '
    query << 'duration ' + operator + ' ' + duration + ' ' + and_operator
  end

  where(query)
end