rack-serverinfo 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rack/serverinfo.rb +63 -21
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ef986a1dda9c34385e4fa8e92025b118a18aa46
4
- data.tar.gz: 45267c03a0a0bf39a4aa9f3b3827b2ac83d56382
3
+ metadata.gz: 43d31a0259e387b22b4221ed71d3e720dcbc31bb
4
+ data.tar.gz: 6e4451af4414912abeb0f173fd0a639717a37df0
5
5
  SHA512:
6
- metadata.gz: 618b426d318e5e24cfe3cf05cf80ec36ff44cb7ff8e0e6f889e22f15f7dd94fbacda1d7924c0b9873c7c3484bb7a2c017a68e4e935152fa75c35d42bf93055ad
7
- data.tar.gz: 49cad9fc6e2489b32e0eab2326cc72da068392d5f14ae59e5740db10ba8880b1c7e775e349c172399638a15afeccd45ec086b6e093d1ce4f394877ca637d3f2e
6
+ metadata.gz: b540e6b2e0f639506a5838a4bcd47fd1f47b01edfef17cac21fcd4135b84fbbf2dee66fe6302d8078631ae8044f8a8f9d2166ada2a10e8eccbc2cf7a60a65d83
7
+ data.tar.gz: 2e4548b4f0d7b4b4270ed157f2c1accc81b5e458c1de6d7141f19f4a7edb60892fa654de3f8ddaf14b47b4757dd6d72801dd53e35cfe8260a272679979ab306d
@@ -5,13 +5,27 @@ module Rack
5
5
 
6
6
  class Serverinfo < Plastic
7
7
 
8
+ DatabaseYamlPath = 'config/database.yml'
9
+
8
10
  def change_nokogiri_doc(doc)
9
11
  return doc if request.xhr?
10
12
 
11
- badge = doc.create_element 'div', style: style
13
+ badge = doc.create_element 'div', style: badge_style
14
+
15
+ badge.add_child(doc.create_element('pre', server_info_text, style: pre_style))
16
+
17
+ if db_connection_config.empty?
18
+ badge.add_child(doc.create_element('pre', "DB: database.yml does not exist", style: pre_style))
19
+ else
20
+ db_detail_container = doc.create_element 'details'
12
21
 
13
- server_info_text.each do |info|
14
- badge.add_child(doc.create_element('p', info, style: 'margin: 0'))
22
+ db_detail_container.add_child(doc.create_element('summary', "DB: #{db_connection_config['database']}"))
23
+
24
+ db_connection_config.each do |key, value|
25
+ db_detail_container.add_child(doc.create_element('p', "#{key}: #{value}", style: "padding-left: 9.5px;margin: 0;"))
26
+ end
27
+
28
+ badge.add_child(db_detail_container)
15
29
  end
16
30
 
17
31
  append_to_body(doc, badge)
@@ -23,25 +37,53 @@ module Rack
23
37
 
24
38
  def server_info_text
25
39
  @server_info_text ||= [
26
- "Hostname: #{hostname}",
27
- "User: #{user.name}",
28
- "Rails-Env: #{rails_env}",
29
- ]
40
+ "Hostname: #{hostname}",
41
+ "User: #{user.name}",
42
+ "RAILS_ENV: #{rails_env}",
43
+ ].join("\n")
44
+ end
45
+
46
+ def pre_style
47
+ @pre_style ||= <<-pre_style
48
+ display: block;
49
+ padding: 0 0 0 9.5px;
50
+ margin: 0;
51
+ font-size: 10px;
52
+ line-height: 12px;
53
+ word-break: break-all;
54
+ word-wrap: break-word;
55
+ white-space: pre;
56
+ white-space: pre-wrap;
57
+ background-color: black;
58
+ pre_style
59
+ end
60
+
61
+ def badge_style
62
+ @badge_style ||= [
63
+ 'position: absolute',
64
+ 'bottom: 10px',
65
+ 'right: 10px',
66
+ 'border: 4px solid red',
67
+ 'padding: 5px',
68
+ 'border-radius: 5px',
69
+ 'background-color: black',
70
+ 'opacity: 0.5',
71
+ 'color: white',
72
+ 'font-size: 10px',
73
+ 'font-family: monospace',
74
+ ].join(';')
30
75
  end
31
76
 
32
- def style
33
- @style ||= [
34
- 'position: absolute;',
35
- 'bottom: 10px;',
36
- 'right: 10px;',
37
- 'border: 4px solid red;',
38
- 'padding: 5px;',
39
- 'border-radius: 5px;',
40
- 'background-color: black;',
41
- 'opacity: 0.5;',
42
- 'color: white;',
43
- 'font-size: 10px;',
44
- ].join
77
+ def db_name
78
+ @db_name ||= db_connection_config['database']
79
+ end
80
+
81
+ def db_connection_config
82
+ @db_connection_config ||= if ::File.file?(DatabaseYamlPath)
83
+ YAML.load_file(DatabaseYamlPath)[rails_env]
84
+ else
85
+ {}
86
+ end
45
87
  end
46
88
 
47
89
  def user
@@ -49,7 +91,7 @@ module Rack
49
91
  end
50
92
 
51
93
  def rails_env
52
- @rails_env ||= ENV['RAILS_ENV']
94
+ @rails_env ||= (ENV['RAILS_ENV'] || 'not set')
53
95
  end
54
96
 
55
97
  def hostname
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-serverinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Simecek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-plastic
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.4.1
83
+ rubygems_version: 2.4.5
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Show information of the app.