class Rubotnik::UserStore

In-memory storage for users

Attributes

users[R]

Public Class Methods

new() click to toggle source
# File lib/rubotnik/user_store.rb, line 8
def initialize
  @users = []
end

Public Instance Methods

add(user) click to toggle source
# File lib/rubotnik/user_store.rb, line 16
def add(user)
  @users << user
  user = @users.last
  if user
    Rubotnik.logger.info "user #{user.inspect} added to store"
    Rubotnik.logger.info "we got #{@users.count} users: #{@users}"
  else
    Rubotnik.logger.info 'user not found in store yet'
  end
  user
end
find(id) click to toggle source
# File lib/rubotnik/user_store.rb, line 28
def find(id)
  user = @users.find { |u| u.id == id }
  Rubotnik.logger.info "user #{user} found in store" if user
  Rubotnik.logger.info "we got #{@users.count} users: #{@users}" if user
  user
end
find_or_create_user(id) click to toggle source
# File lib/rubotnik/user_store.rb, line 12
def find_or_create_user(id)
  find(id) || add(Rubotnik::User.new(id))
end