Sha256: 423aa18ec3e50ee489b9bff50f72daa9c4ec0f9a039db51aa525f0d04827ee6c

Contents?: true

Size: 458 Bytes

Versions: 13

Compression:

Stored size: 458 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

13 entries across 13 versions & 1 rubygems

Version Path
introspective_grape-0.3.2 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.1 spec/dummy/app/models/chat_user.rb
introspective_grape-0.3.0 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.9 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.8 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.7 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.6 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.5 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.4 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.3 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.2 spec/dummy/app/models/chat_user.rb
introspective_grape-0.2.0 spec/dummy/app/models/chat_user.rb
introspective_grape-0.1.9 spec/dummy/app/models/chat_user.rb