Class: Dev::TargetProcess::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/firespring_dev_commands/target_process/query.rb

Overview

Class for writing target process query statements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuery

Returns a new instance of Query.



7
8
9
10
11
# File 'lib/firespring_dev_commands/target_process/query.rb', line 7

def initialize
  @where = []
  @incl = []
  @take = 250
end

Instance Attribute Details

#inclObject

Returns the value of attribute incl.



5
6
7
# File 'lib/firespring_dev_commands/target_process/query.rb', line 5

def incl
  @incl
end

#takeObject

Returns the value of attribute take.



5
6
7
# File 'lib/firespring_dev_commands/target_process/query.rb', line 5

def take
  @take
end

#whereObject

Returns the value of attribute where.



5
6
7
# File 'lib/firespring_dev_commands/target_process/query.rb', line 5

def where
  @where
end

Instance Method Details

#<<(item) ⇒ Object

Add a new query clause



14
15
16
# File 'lib/firespring_dev_commands/target_process/query.rb', line 14

def <<(item)
  where << item
end

#filter_by_deploy_date(start_date, end_date = nil) ⇒ Object

Add a filter that looks for a custom deploy date between the given dates`



116
117
118
119
# File 'lib/firespring_dev_commands/target_process/query.rb', line 116

def filter_by_deploy_date(start_date, end_date = nil)
  self << "('CustomFields.Deploy Date' gt '#{start_date}')" if start_date
  self << "('CustomFields.Deploy Date' lt '#{end_date}')" if end_date
end

#filter_by_entity_ids(entity_ids) ⇒ Object

Add a filter that looks for assignable ids which are included in the given array



111
112
113
# File 'lib/firespring_dev_commands/target_process/query.rb', line 111

def filter_by_entity_ids(entity_ids)
  self << "(Assignable.Id in ('#{entity_ids.join("', '")}'))" unless entity_ids.nil? || entity_ids.empty?
end

#filter_by_entity_type(entity_type) ⇒ Object

Add a filter that looks for assignable entity types that match the name



106
107
108
# File 'lib/firespring_dev_commands/target_process/query.rb', line 106

def filter_by_entity_type(entity_type)
  self << "(Assignable.EntityType.Name eq '#{entity_type}')" unless entity_type.nil?
end

#filter_by_finalObject

Add a filter that looks for stories whose state is set to final



72
73
74
# File 'lib/firespring_dev_commands/target_process/query.rb', line 72

def filter_by_final
  self << "(EntityState.IsFinal eq 'true')"
end

#filter_by_missing_testsObject

Add a filter that looks for stories which do not have a linked test plan



95
96
97
# File 'lib/firespring_dev_commands/target_process/query.rb', line 95

def filter_by_missing_tests
  self << '(LinkedTestPlan is nil)'
end

#filter_by_project(projects) ⇒ Object

Add a filter that looks for stories whose project id is contained in the list of ids given



62
63
64
# File 'lib/firespring_dev_commands/target_process/query.rb', line 62

def filter_by_project(projects)
  self << "(Project.Name in ('#{projects.join("', '")}'))"
end

#filter_by_started_not_finishedObject

Add a filter that looks for items with a set start date and null end date



100
101
102
103
# File 'lib/firespring_dev_commands/target_process/query.rb', line 100

def filter_by_started_not_finished
  self << '(StartDate is not nil)'
  self << '(EndDate is nil)'
end

#filter_by_states(states) ⇒ Object

Add a filter that looks for stories whose state is contained in the list of states given



67
68
69
# File 'lib/firespring_dev_commands/target_process/query.rb', line 67

def filter_by_states(states)
  self << "(EntityState.Name in ('#{states.join("', '")}'))" unless states.nil? || states.empty?
end

#filter_by_team_ids(team_ids) ⇒ Object

Add a filter that looks for stories whose team id is contained in the list of ids given



57
58
59
# File 'lib/firespring_dev_commands/target_process/query.rb', line 57

def filter_by_team_ids(team_ids)
  self << "(Team.Id in ('#{team_ids.join("', '")}'))" unless team_ids.nil? || team_ids.empty?
end

#filter_by_user_story_ids(user_story_ids) ⇒ Object

TODO: Do these need moved to their associated entities? Add a filter that looks for stories whose id is contained in the list of ids given



52
53
54
# File 'lib/firespring_dev_commands/target_process/query.rb', line 52

def filter_by_user_story_ids(user_story_ids)
  self << "(Id in ('#{user_story_ids.join("', '")}'))"
end

#filter_date_between(start_date, end_date) ⇒ Object

Add a filter that looks for entities whose date is between the given dates



89
90
91
92
# File 'lib/firespring_dev_commands/target_process/query.rb', line 89

def filter_date_between(start_date, end_date)
  self << "(Date gte '#{start_date}')" if start_date
  self << "(Date lt '#{end_date}')" if end_date
end

#filter_end_date_between(start_date, end_date) ⇒ Object

Add a filter that looks for stories whose end date is between the given dates



83
84
85
86
# File 'lib/firespring_dev_commands/target_process/query.rb', line 83

def filter_end_date_between(start_date, end_date)
  self << "(EndDate gte '#{start_date}')" if start_date
  self << "(EndDate lt '#{end_date}')" if end_date
end

#filter_start_date_between(start_date, end_date) ⇒ Object

Add a filter that looks for start dates between the given dates`



77
78
79
80
# File 'lib/firespring_dev_commands/target_process/query.rb', line 77

def filter_start_date_between(start_date, end_date)
  self << "(StartDate gte '#{start_date}')" if start_date
  self << "(StartDate lt '#{end_date}')" if end_date
end

#generateObject

Generate the string representation for this query



37
38
39
40
41
42
43
# File 'lib/firespring_dev_commands/target_process/query.rb', line 37

def generate
  {}.tap do |clause|
    clause[:where] = where.join(' and ') unless where.nil? || where.empty?
    clause[:include] = "[#{incl.join(',')}]" unless incl.nil? || incl.empty?
    clause[:take] = take if take.to_i.positive?
  end
end

#include=(item) ⇒ Object

Add the item to the include clause



28
29
30
31
32
33
34
# File 'lib/firespring_dev_commands/target_process/query.rb', line 28

def include=(item)
  if item.is_a?(Array)
    incl.concat(item)
  else
    incl << item
  end
end

#to_sObject

Generate the string representation for this query



46
47
48
# File 'lib/firespring_dev_commands/target_process/query.rb', line 46

def to_s
  generate
end