Sha256: 4c001492306e131bd54460fcb32d08031f2ca8fe6385c090ea318c85c28a2b1b

Contents?: true

Size: 587 Bytes

Versions: 49

Compression:

Stored size: 587 Bytes

Contents

class TicketAssignment
  attr_reader :assigned_ids, :unassigned_ids

  def initialize ticket, user_ids
    @ticket = ticket
    @user_ids = user_ids.split(",")
  end

  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
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
tawork-0.0.9 lib/ticket_assignment.rb
tawork-0.0.8 lib/ticket_assignment.rb
tawork-0.0.7 lib/ticket_assignment.rb
tawork-0.0.6 lib/ticket_assignment.rb
tawork-0.0.5 lib/ticket_assignment.rb
tawork-0.0.4 lib/ticket_assignment.rb
tawork-0.0.3 lib/ticket_assignment.rb
tawork-0.0.2 lib/ticket_assignment.rb
tawork-0.0.1 lib/ticket_assignment.rb