Module: SPAssignmentManager

Included in:
AssignsController
Defined in:
app/helpers/sp_assignment_manager.rb

Instance Method Summary collapse

Instance Method Details

#_unassign(project) ⇒ Object



16
17
18
# File 'app/helpers/sp_assignment_manager.rb', line 16

def _unassign(project)
	project.assigns.find_by(assigned: true)&.terminate # ruby >= 2.3.0 "safe navigation operator"
end

#assign_to(service_pack, project) ⇒ Object

Implementation is subject to change.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/sp_assignment_manager.rb', line 3

def assign_to(service_pack, project)
	# binding.pry
	ActiveRecord::Base.transaction do
		# one query only
		project.assigns.update_all(assigned: false)
		@assignment = service_pack.assigns.find_by(project_id: project.id) || project.assigns.new
		@assignment.assigned = true
		@assignment.assign_date = Date.today
		@assignment.unassign_date = service_pack.expired_date
		@assignment.service_pack_id = service_pack.id if @assignment.new_record?
		@assignment.save!
	end
end

#assigned?(project) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/helpers/sp_assignment_manager.rb', line 22

def assigned?(project)
	project.assigns.find_by(assigned: true)
end

#unassigned?(project) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/helpers/sp_assignment_manager.rb', line 19

def unassigned?(project)
	!assigned?(project)
end