Sha256: b5c310b56c0183de0a169bed2d9bf15d92f8d0e7361757b3418a052ad6427577

Contents?: true

Size: 457 Bytes

Versions: 15

Compression:

Stored size: 457 Bytes

Contents

class ChatUser < AbstractAdapter
  belongs_to :chat
  belongs_to :user

  alias_attribute :joined_at, :created_at
  alias_attribute :left_at,   :departed_at

  scope :current, ->{ where(departed_at: nil) }

  validate :user_not_already_active, on: :create

  def user_not_already_active
    errors[:base] << "#{user.name} is already present in this chat." if chat.chat_users.where(user_id: user.id, departed_at: nil).count > 0 && user.persisted?
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
introspective_grape-0.5.7 spec/dummy/app/models/chat_user.rb
introspective_grape-0.5.6 spec/dummy/app/models/chat_user.rb
introspective_grape-0.5.5 spec/dummy/app/models/chat_user.rb
introspective_grape-0.5.4 spec/dummy/app/models/chat_user.rb
introspective_grape-0.5.2 spec/dummy/app/models/chat_user.rb
introspective_grape-0.5.0 spec/dummy/app/models/chat_user.rb
introspective_grape-0.4.3 spec/dummy/app/models/chat_user.rb
introspective_grape-0.4.2 spec/dummy/app/models/chat_user.rb
introspective_grape-0.4.1 spec/dummy/app/models/chat_user.rb
introspective_grape-0.4.0 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.9 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.7 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.6 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.5 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.3 spec/dummy/app/models/chat_user.rb