class RollbarSearchUrl::Query

Public Class Methods

new(user: "", project: "") click to toggle source
# File lib/rollbar_search_url.rb, line 9
def initialize user: "", project: ""
  raise ArgumentError if user.nil? || project.nil? || user.empty? || project.empty?
  @user     = user
  @project  = project
  @where    = []
  @select   = []
  @limit    = nil
  @order_by = ""
  @group_by = ""
end

Public Instance Methods

group_by(group_by_statement) click to toggle source
# File lib/rollbar_search_url.rb, line 30
def group_by group_by_statement
  @group_by = group_by_statement
  self
end
limit(limit) click to toggle source
# File lib/rollbar_search_url.rb, line 40
def limit limit
  @limit = limit
  self
end
order_by(order_by_statement) click to toggle source
# File lib/rollbar_search_url.rb, line 35
def order_by order_by_statement
  @order_by = order_by_statement
  self
end
select(select_statement) click to toggle source
# File lib/rollbar_search_url.rb, line 20
def select select_statement
  @select << select_statement
  self
end
url() click to toggle source
# File lib/rollbar_search_url.rb, line 45
def url
  URI.escape(BASE_URL % {user: @user, project: @project} + "?q=#{query}")
end
where(where_statement) click to toggle source
# File lib/rollbar_search_url.rb, line 25
def where where_statement
  @where << where_statement
  self
end

Private Instance Methods

query() click to toggle source
# File lib/rollbar_search_url.rb, line 51
def query
  statements = []
  statements << "select"
  statements << (@select.empty? ? ['*'] : @select).join(', ')
  statements << "from item_occurrence"
  statements << "where #{@where.join ' and '} " unless @where.empty?
  statements << "group by #{@group_by}" unless @group_by.empty?
  statements << "order by #{@order_by}" unless @order_by.empty?
  statements << "limit #{@limit}" unless @limit.nil?

  statements.join ' '
end