Class: Files::SystemProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/system_profiler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystemProfiler

Returns a new instance of SystemProfiler.



36
37
38
# File 'lib/files.com/system_profiler.rb', line 36

def initialize
  @uname = self.class.uname
end

Class Method Details

.unameObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/files.com/system_profiler.rb', line 5

def self.uname
  if ::File.exist?("/proc/version")
    ::File.read("/proc/version").strip
  else
    case RbConfig::CONFIG["host_os"]
    when /linux|darwin|bsd|sunos|solaris|cygwin/i
      uname_from_system
    when /mswin|mingw/i
      uname_from_system_ver
    else
      "unknown platform"
    end
  end
end

.uname_from_systemObject



20
21
22
23
24
25
26
# File 'lib/files.com/system_profiler.rb', line 20

def self.uname_from_system
  (`uname -a 2>/dev/null` || "").strip
rescue Errno::ENOENT
  "uname executable not found"
rescue Errno::ENOMEM # couldn't create subprocess
  "uname lookup failed"
end

.uname_from_system_verObject



28
29
30
31
32
33
34
# File 'lib/files.com/system_profiler.rb', line 28

def self.uname_from_system_ver
  (`ver` || "").strip
rescue Errno::ENOENT
  "ver executable not found"
rescue Errno::ENOMEM # couldn't create subprocess
  "uname lookup failed"
end

Instance Method Details

#user_agentObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/files.com/system_profiler.rb', line 40

def user_agent
  lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"

  {
    application: Files.app_info,
    bindings_version: Files::VERSION,
    lang: "ruby",
    lang_version: lang_version,
    platform: RUBY_PLATFORM,
    engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
    publisher: "Action Verb LLC",
    uname: @uname,
    hostname: Socket.gethostname,
  }.delete_if { |_k, v| v.nil? }
end