Class: ArtisanMemoryRepository::UserRepository

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

Instance Method Summary collapse

Methods included from BaseRepository

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

Instance Method Details

#active_stories_for(user) ⇒ Object



33
34
35
36
37
# File 'lib/artisan-memory-repository/user_repository.rb', line 33

def active_stories_for(user)
  story_repository = Artisan::Repository.story
  stories = story_repository.for_user(user)
  stories.reject { |story| story.complete }
end

#create(attrs = {}) ⇒ Object



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

def create(attrs = {})
  user = new(attrs)
  if !existing_login?(user.) && user.valid?
    save(user)
  else
    user.add_error(:login, 'has already been taken')
    raise Artisan::RecordNotValid.new(user)
  end
  user
end

#find_by_email(email) ⇒ Object



24
25
26
# File 'lib/artisan-memory-repository/user_repository.rb', line 24

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

#find_by_login(login) ⇒ Object



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

def ()
  return nil if .nil?
  records.values.find { |r| r..downcase == .downcase  }
end

#new(attrs = {}) ⇒ Object



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

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