Class: Bicho::Query

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bicho/query.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conditions = {}) ⇒ Query

Create a query.

Examples:

query from a hash containing the attributes:

q = Query.new({:summary => "substring", :assigned_to => "[email protected]"})

using chainable methods:

q = Query.new.assigned_to("[email protected]@).summary("some text")


60
61
62
# File 'lib/bicho/query.rb', line 60

def initialize(conditions = {})
  @query_map = conditions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Query responds to all the bug search attributes.

See Also:

  • Allowed attributes}


67
68
69
70
71
72
73
74
75
# 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

Instance Attribute Details

#query_mapObject (readonly)

obtains the parameter that can be passed to the XMLRPC API



50
51
52
# File 'lib/bicho/query.rb', line 50

def query_map
  @query_map
end

Instance Method Details

#each {|Bicho::Bug| ... } ⇒ Object

Note:

Requires Bicho.client to be set

Iterates through the result of the current query.

Yields:



42
43
44
45
46
# 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

#L3Object

Shortcut, equivalent to

:summary => "L3"


88
89
90
91
# File 'lib/bicho/query.rb', line 88

def L3 # rubocop:disable Naming/MethodName
  append_query('summary', 'L3')
  self
end

#openObject

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



82
83
84
# 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) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# 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