Class: FocusCommon::AppInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/focus_common/app_info.rb

Instance Method Summary collapse

Instance Method Details

#get_database_time_infoObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/focus_common/app_info.rb', line 3

def get_database_time_info
  conn = ActiveRecord::Base.connection
  if conn.class.name.demodulize == 'Mysql2Adapter'
    {zone: conn.execute("SELECT @@global.time_zone, @@session.time_zone;").to_a.flatten,
     time: conn.execute("select concat(now(), '');").to_a.flatten.first,
    }
  else
    {}
  end
end

#get_gemsObject



69
70
71
# File 'lib/focus_common/app_info.rb', line 69

def get_gems
  Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }
end

#get_infoObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/focus_common/app_info.rb', line 27

def get_info
  db_time_info = self.get_database_time_info
  info = \
  {
    environment: {
      rails: Rails.env,
      stage: ENV['STAGE'],
    },
    version: {
      ruby: RUBY_VERSION,
      rails: Rails::VERSION::STRING,
      git: git_version,
    },
    time: {
      system: {
        time: Time.now.to_s,
        zone: Time.now.zone,
      },
      rails: {
        time: Time.zone.now,
        zone: Time.zone.to_s,
      },
      database: {
        time: db_time_info[:time],
        global_zone: db_time_info[:zone].try(:first),
        session_zone: db_time_info[:zone].try(:second),
      },
    },
    important_gems: get_gems.map{|g| [g.name, g.version]}.to_h.slice('sidekiq'),
  }

  if defined?(CbaDB)
    info[:cba_site] = \
    CbaDB.enabled_sites.map do |site|
      namespace = CbaDB.sites_info.fetch(site, {})[:db_name]
      [site, namespace]
    end.to_h
  end

  info
end

#git_versionObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/focus_common/app_info.rb', line 14

def git_version
  if Rails.env.development?
    `git rev-parse HEAD`
  else
    filename = File.join(Rails.root, 'REVISION')
    if File.exists?(filename)
      File.read(filename).strip
    else
      nil
    end
  end
end