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
12
# File 'lib/firespring_dev_commands/target_process/query.rb', line 7

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

Instance Attribute Details

#emptyObject

Returns the value of attribute empty.



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

def empty
  @empty
end

#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



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

def <<(item)
  where << item
end

#empty?Boolean

Check if any of the “in” statements were empty. If so then we don’t want to actually run the query

Returns:

  • (Boolean)


38
39
40
# File 'lib/firespring_dev_commands/target_process/query.rb', line 38

def empty?
  @empty == true
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`



147
148
149
150
# File 'lib/firespring_dev_commands/target_process/query.rb', line 147

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_id(entity_id) ⇒ Object

Add a filter that looks for assignable id that match the given id



133
134
135
# File 'lib/firespring_dev_commands/target_process/query.rb', line 133

def filter_by_entity_id(entity_id)
  self << "(Assignable.Id eq '#{entity_id}')" unless entity_id.nil?
end

#filter_by_entity_ids(entity_ids) ⇒ Object

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



138
139
140
141
142
143
144
# File 'lib/firespring_dev_commands/target_process/query.rb', line 138

def filter_by_entity_ids(entity_ids)
  if entity_ids.nil? || entity_ids.empty?
    @empty = true
    return
  end
  self << "(Assignable.Id in ('#{entity_ids.join("', '")}'))"
end

#filter_by_entity_type(entity_type) ⇒ Object

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



128
129
130
# File 'lib/firespring_dev_commands/target_process/query.rb', line 128

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



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

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



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

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



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

def filter_by_project(projects)
  if projects.nil? || projects.empty?
    @empty = true
    return
  end
  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



122
123
124
125
# File 'lib/firespring_dev_commands/target_process/query.rb', line 122

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



85
86
87
88
89
90
91
# File 'lib/firespring_dev_commands/target_process/query.rb', line 85

def filter_by_states(states)
  if states.nil? || states.empty?
    @empty = true
    return
  end
  self << "(EntityState.Name in ('#{states.join("', '")}'))"
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



67
68
69
70
71
72
73
# File 'lib/firespring_dev_commands/target_process/query.rb', line 67

def filter_by_team_ids(team_ids)
  if team_ids.nil? || team_ids.empty?
    @empty = true
    return
  end
  self << "(Team.Id in ('#{team_ids.join("', '")}'))"
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



58
59
60
61
62
63
64
# File 'lib/firespring_dev_commands/target_process/query.rb', line 58

def filter_by_user_story_ids(user_story_ids)
  if user_story_ids.nil? || user_story_ids.empty?
    @empty = true
    return
  end
  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



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

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



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

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`



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

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



43
44
45
46
47
48
49
# File 'lib/firespring_dev_commands/target_process/query.rb', line 43

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



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

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



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

def to_s
  generate
end