class Bicho::Query

Represents a bug search to the server and it can be configured with all bug attributes.

Attributes

query_map[R]

obtains the parameter that can be passed to the XMLRPC API @private

Public Class Methods

new(conditions = {}) click to toggle source

Create a query.

@example query from a hash containing the attributes:

q = Query.new({:summary => "substring", :assigned_to => "foo@bar.com"})

@example using chainable methods:

q = Query.new.assigned_to("foo@bar.com@).summary("some text")
# File lib/bicho/query.rb, line 60
def initialize(conditions = {})
  @query_map = conditions
end

Public Instance Methods

L3() click to toggle source

Shortcut, equivalent to

:summary => "L3"
# File lib/bicho/query.rb, line 88
def L3 # rubocop:disable Naming/MethodName
  append_query('summary', 'L3')
  self
end
each() { |bug| ... } click to toggle source

Iterates through the result of the current query.

@note Requires Bicho.client to be set

@yield [Bicho::Bug]

# File lib/bicho/query.rb, line 42
def each
  ret = Bicho.client.search_bugs(self)
  return ret.each unless block_given?
  ret.each { |bug| yield bug }
end
method_missing(method_name, *args) click to toggle source

Query responds to all the bug search attributes.

@see {Bug.where Allowed attributes}

Calls superclass method
# File lib/bicho/query.rb, line 67
def method_missing(method_name, *args)
  return super unless Bicho::SEARCH_FIELDS
                      .map(&:first)
                      .include?(method_name)
  args.each do |arg|
    append_query(method_name.to_s, arg)
  end
  self
end
open() click to toggle source

Shortcut equivalent to status new, assigned, needinfo, reopened, confirmed, and in_progress

# File lib/bicho/query.rb, line 82
def open
  status(:new).status(:assigned).status(:needinfo).status(:reopened).status(:confirmed).status(:in_progress)
end
respond_to_missing?(method_name, _include_private = false) click to toggle source
Calls superclass method
# File lib/bicho/query.rb, line 77
def respond_to_missing?(method_name, _include_private = false)
  Bicho::SEARCH_FIELDS.map(&:first).include?(method_name) || super
end

Private Instance Methods

append_query(param, value) click to toggle source

Appends a parameter to the query map

Only used internally.

If the parameter already exists that parameter is converted to an array of values

@private

# File lib/bicho/query.rb, line 103
def append_query(param, value)
  @query_map[param] = [] unless @query_map.key?(param)
  @query_map[param] = [@query_map[param], value].flatten
end