Module: Donjon::User::ClassMethods

Included in:
Donjon::User
Defined in:
lib/donjon/user.rb

Instance Method Summary collapse

Instance Method Details

#each(repo, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/donjon/user.rb', line 44

def each(repo, &block)
  container = repo.join('users')
  return unless container.exist?
  container.children.each do |child|
    next unless child.extname == '.pub'
    name = child.basename.to_s.chomp('.pub')
    key = OpenSSL::PKey::RSA.new(child.read)
    block.call new(name: name, key: key, repo: repo)
  end
end

#find(name:, repo:) ⇒ Object



37
38
39
40
41
42
# File 'lib/donjon/user.rb', line 37

def find(name:, repo:)
  path = _path_for(name, repo)
  return unless path.exist?
  key = OpenSSL::PKey::RSA.new(path.read)
  new(name: name, key: key, repo: repo)
end