Class: TicketAssignment
- Inherits:
-
Object
- Object
- TicketAssignment
- Defined in:
- lib/ticket_assignment.rb
Instance Attribute Summary collapse
-
#assigned_ids ⇒ Object
readonly
Returns the value of attribute assigned_ids.
-
#unassigned_ids ⇒ Object
readonly
Returns the value of attribute unassigned_ids.
Instance Method Summary collapse
- #assign! ⇒ Object
-
#initialize(ticket, user_ids) ⇒ TicketAssignment
constructor
A new instance of TicketAssignment.
Constructor Details
#initialize(ticket, user_ids) ⇒ TicketAssignment
4 5 6 7 |
# File 'lib/ticket_assignment.rb', line 4 def initialize ticket, user_ids @ticket = ticket @user_ids = user_ids.split(",") end |
Instance Attribute Details
#assigned_ids ⇒ Object (readonly)
Returns the value of attribute assigned_ids.
2 3 4 |
# File 'lib/ticket_assignment.rb', line 2 def assigned_ids @assigned_ids end |
#unassigned_ids ⇒ Object (readonly)
Returns the value of attribute unassigned_ids.
2 3 4 |
# File 'lib/ticket_assignment.rb', line 2 def unassigned_ids @unassigned_ids end |
Instance Method Details
#assign! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ticket_assignment.rb', line 9 def assign! ids = @user_ids existing_ids = @ticket.assignments.map(&:user_id) @unassigned_ids = existing_ids - ids if @unassigned_ids.any? @ticket.assignments.where(user_id: @unassigned_ids).destroy_all end @assigned_ids = ids - existing_ids @assigned_ids.each do |id| @ticket.assignments.create(user_id: id) end @assigned_ids.any? || @unassigned_ids.any? end |