better abstraction for system infos

This commit is contained in:
Alexander Meindl 2021-09-03 17:42:57 +02:00
parent c190c504b6
commit bc9054b615
3 changed files with 77 additions and 69 deletions

View File

@ -3,10 +3,12 @@
class AdditionalsInfo
include Redmine::I18n
class << self
def system_infos
{ system_info: { label: l(:label_system_info), value: system_info },
system_uptime: { label: l(:label_uptime), value: system_uptime } }
{ system_info: { label: l(:label_system_info),
value: system_info },
system_uptime: { label: l(:label_uptime),
value: system_uptime,
api_value: system_uptime(format: :datetime) } }
end
def system_info
@ -71,5 +73,4 @@ class AdditionalsInfo
def windows_platform?
/cygwin|mswin|mingw|bccwin|wince|emx/.match? RUBY_PLATFORM
end
end
end

View File

@ -1,6 +1,13 @@
table.list
- AdditionalsInfo.system_infos.each_value do |system_info|
tr
- AdditionalsInfo.new.system_infos.each do |type, system_info|
tr class=type
td.name
= "#{system_info[:label]}:"
td.name = system_info[:value]
= "#{system_info[:label].presence || type}:"
td.name
- case system_info[:value]
- when true
= image_tag 'true.png'
- when false
= image_tag 'exclamation.png'
- else
= system_info[:value]

View File

@ -4,12 +4,12 @@ require File.expand_path '../../test_helper', __FILE__
class AdditionalsInfoTest < Additionals::TestCase
def test_system_info
text = AdditionalsInfo.system_info
text = AdditionalsInfo.new.system_info
assert_not_equal '', text
assert_not_equal 'unknown', text
end
def test_windows_platform
assert_not AdditionalsInfo.windows_platform?
assert_not AdditionalsInfo.new.windows_platform?
end
end