Class: FocusCommon::AppInfo
- Inherits:
-
Object
- Object
- FocusCommon::AppInfo
- Defined in:
- lib/focus_common/app_info.rb
Instance Method Summary collapse
- #get_database_info ⇒ Object
- #get_database_time_info ⇒ Object
- #get_gems ⇒ Object
- #get_info ⇒ Object
- #git_version ⇒ Object
- #important_gems ⇒ Object
Instance Method Details
#get_database_info ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/focus_common/app_info.rb', line 14 def get_database_info conn = ActiveRecord::Base.connection adapter = conn.adapter_name sql = \ case adapter when "MSSQL" "SELECT @@VERSION" when "MySQL", "Mysql2", "PostgreSQL" "SELECT VERSION()" when "SQLServer" "SELECT @@VERSION" when "OracleEnhanced" "SELECT * FROM V$VERSION" when "SQLite" "SELECT SQLITE_VERSION()" else nil end v = sql ? conn.select_value(sql) : nil {version: v} end |
#get_database_time_info ⇒ Object
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_gems ⇒ Object
102 103 104 |
# File 'lib/focus_common/app_info.rb', line 102 def get_gems Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] } end |
#get_info ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/focus_common/app_info.rb', line 51 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, database: self.get_database_info[: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(*self.important_gems), } 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_version ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/focus_common/app_info.rb', line 38 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 |
#important_gems ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/focus_common/app_info.rb', line 94 def important_gems ['sidekiq', 'grape', 'elasticsearch', 'twitter-bootstrap-rails', ] end |