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.29 lib/ticket_assignment.rb
tawork-0.0.28 lib/ticket_assignment.rb
tawork-0.0.27 lib/ticket_assignment.rb
tawork-0.0.26 lib/ticket_assignment.rb
tawork-0.0.25 lib/ticket_assignment.rb
tawork-0.0.24 lib/ticket_assignment.rb
tawork-0.0.23 lib/ticket_assignment.rb
tawork-0.0.22 lib/ticket_assignment.rb
tawork-0.0.21 lib/ticket_assignment.rb
tawork-0.0.20 lib/ticket_assignment.rb
tawork-0.0.19 lib/ticket_assignment.rb
tawork-0.0.18 lib/ticket_assignment.rb
tawork-0.0.17 lib/ticket_assignment.rb
tawork-0.0.16 lib/ticket_assignment.rb
tawork-0.0.15 lib/ticket_assignment.rb
tawork-0.0.14 lib/ticket_assignment.rb
tawork-0.0.13 lib/ticket_assignment.rb
tawork-0.0.12 lib/ticket_assignment.rb
tawork-0.0.11 lib/ticket_assignment.rb
tawork-0.0.10 lib/ticket_assignment.rb