Class: ArtisanMemoryRepository::FutureUserRepository

Inherits:
Object
  • Object
show all
Includes:
BaseRepository
Defined in:
lib/artisan-memory-repository/future_user_repository.rb

Instance Method Summary collapse

Methods included from BaseRepository

#delete, #destroy_all, #find, #find_each, #records, #save, #where

Instance Method Details

#create(attrs = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/artisan-memory-repository/future_user_repository.rb', line 13

def create(attrs = {})
  future_user = new(attrs)
  unique_email = validate_unique_email(attrs[:email])
  if unique_email
    save(future_user)
  else
    future_user.add_errors(:email => "This email has already been taken")
    raise Artisan::RecordNotValid.new(future_user)
  end
  future_user
end

#find_by_email(email) ⇒ Object



25
26
27
# File 'lib/artisan-memory-repository/future_user_repository.rb', line 25

def find_by_email(email)
  records.values.find { |r| r.email == email }
end

#find_by_project_id(project_id) ⇒ Object



29
30
31
# File 'lib/artisan-memory-repository/future_user_repository.rb', line 29

def find_by_project_id(project_id)
  records.values.find { |r| r.project_id == project_id }
end

#new(attrs = {}) ⇒ Object



9
10
11
# File 'lib/artisan-memory-repository/future_user_repository.rb', line 9

def new(attrs = {})
  ArtisanMemoryRepository::FutureUser.new(attrs)
end