Class: Appsignal::CLI::Diagnose::Utils
- Defined in:
- lib/appsignal/cli/diagnose/utils.rb
Overview
Class Method Summary collapse
- .group_for_gid(gid) ⇒ Object
- .read_file_content(path, bytes_to_read) ⇒ Object
- .username_for_uid(uid) ⇒ Object
Class Method Details
.group_for_gid(gid) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/appsignal/cli/diagnose/utils.rb', line 15 def self.group_for_gid(gid) passwd_struct = Etc.getgrgid(gid) return unless passwd_struct passwd_struct.name rescue ArgumentError # rubocop:disable Lint/SuppressedException end |
.read_file_content(path, bytes_to_read) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/appsignal/cli/diagnose/utils.rb', line 23 def self.read_file_content(path, bytes_to_read) file_size = File.size(path) if bytes_to_read > file_size # When the file is smaller than the bytes_to_read # Read the whole file offset = 0 length = file_size else # When the file is smaller than the bytes_to_read # Read the last X bytes_to_read length = bytes_to_read offset = file_size - bytes_to_read end File.binread(path, length, offset) end |
.username_for_uid(uid) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/appsignal/cli/diagnose/utils.rb', line 7 def self.username_for_uid(uid) passwd_struct = Etc.getpwuid(uid) return unless passwd_struct passwd_struct.name rescue ArgumentError # rubocop:disable Lint/SuppressedException end |