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.50 lib/ticket_assignment.rb
tawork-0.0.49 lib/ticket_assignment.rb
tawork-0.0.48 lib/ticket_assignment.rb
tawork-0.0.47 lib/ticket_assignment.rb
tawork-0.0.46 lib/ticket_assignment.rb
tawork-0.0.45 lib/ticket_assignment.rb
tawork-0.0.44 lib/ticket_assignment.rb
tawork-0.0.43 lib/ticket_assignment.rb
tawork-0.0.42 lib/ticket_assignment.rb
tawork-0.0.41 lib/ticket_assignment.rb
tawork-0.0.40 lib/ticket_assignment.rb
tawork-0.0.39 lib/ticket_assignment.rb
tawork-0.0.38 lib/ticket_assignment.rb
tawork-0.0.37 lib/ticket_assignment.rb
tawork-0.0.36 lib/ticket_assignment.rb
tawork-0.0.35 lib/ticket_assignment.rb
tawork-0.0.34 lib/ticket_assignment.rb
tawork-0.0.33 lib/ticket_assignment.rb
tawork-0.0.31 lib/ticket_assignment.rb
tawork-0.0.30 lib/ticket_assignment.rb