Class: ProxyTester::UserDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_tester/user_database.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = ProxyTester.config.user_file) ⇒ UserDatabase

Returns a new instance of UserDatabase.



10
11
12
# File 'lib/proxy_tester/user_database.rb', line 10

def initialize(file = ProxyTester.config.user_file)
  @file = file
end

Instance Method Details

#create_users(creator) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/proxy_tester/user_database.rb', line 14

def create_users(creator)
  fail Exceptions::UserFileNotFound, JSON.dump(file: file) unless ::File.exist? file

  CSV.foreach(file, headers: true) do |r|
    creator.create! name: r['name'], password: r['password']
  end
rescue ActiveRecord::RecordInvalid => err
  raise Exceptions::UserRecordInvalid, JSON.dump(message: err.message)
end