pinfo-rails 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pinfo-rails.rb +46 -26
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4bbcf772faf9e8fecc38536d93d537f5fd4964d
|
4
|
+
data.tar.gz: 09c3aa97fcd7640f18ebf0262274e24235da5deb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f10cf6b8fc148889f5b8d2c9018b084bcceb58394c88a3f3eca2dee1ed2e3790ae1e62434fbc851f607a6d06ad3902f8455ced20b46087c11a7bfe469bb4fa04
|
7
|
+
data.tar.gz: bf4e88813406839c05dec4b8de46748d6362b6ae6b0f9d1f48cd27c97e59482f47ee47dfdc14855a2bb38e6d47e37bd7137e474c97d9d60aec6e48a41b117043
|
data/lib/pinfo-rails.rb
CHANGED
@@ -6,11 +6,11 @@ require 'yaml'
|
|
6
6
|
|
7
7
|
module PinfoRails
|
8
8
|
NAME = 'pinfo-rails'.freeze
|
9
|
-
DATE = '2016-10-
|
9
|
+
DATE = '2016-10-10'.freeze
|
10
10
|
INFO = 'Rails project info'.freeze
|
11
11
|
DESC = 'A gem to collect informations from a Rails project'.freeze
|
12
12
|
AUTHORS = [ [ 'Mattia Roccoberton', 'mat@blocknot.es', 'http://blocknot.es' ] ].freeze
|
13
|
-
VERSION = [ 0, 1,
|
13
|
+
VERSION = [ 0, 1, 4 ].freeze
|
14
14
|
|
15
15
|
FILES = {
|
16
16
|
conf_db: 'config/database.yml',
|
@@ -23,7 +23,7 @@ module PinfoRails
|
|
23
23
|
gemfile: 'Gemfile'
|
24
24
|
}.freeze
|
25
25
|
PATTERNS = {
|
26
|
-
cache:
|
26
|
+
cache: /\A\s*config.cache_classes.*|\A\s*config.action_controller.perform_caching.*/,
|
27
27
|
deploy_info: /branch\s*,.*|user\s*,.*|domain\s*,.*|server[^,]+/,
|
28
28
|
deploy_tool: /'capistrano'|"capistrano|'capistrano-rails'|"capistrano-rails"|'mina'|"mina"/,
|
29
29
|
deploy_user: /user.*/,
|
@@ -36,7 +36,6 @@ module PinfoRails
|
|
36
36
|
def self.info( args )
|
37
37
|
@conf = {}
|
38
38
|
@options = optparse( args )
|
39
|
-
|
40
39
|
@output = ''
|
41
40
|
@output += "[verbose mode]\n" if @options[:verbose]
|
42
41
|
if @options[:conf]
|
@@ -50,12 +49,10 @@ module PinfoRails
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
# Ruby version
|
54
52
|
printline( 'Ruby', { color: :green, mode: :bold }, RUBY_VERSION, @options[:verbose] ? 'p' + RUBY_PATCHLEVEL.to_s : nil )
|
55
|
-
# Rails version
|
56
53
|
printline( 'Rails', { color: :green, mode: :bold }, grep( FILES[:gemfile], PATTERNS[:rails] ) )
|
57
|
-
check_database
|
58
54
|
check_requirements
|
55
|
+
check_database
|
59
56
|
check_cache
|
60
57
|
check_deploy
|
61
58
|
|
@@ -67,14 +64,15 @@ module PinfoRails
|
|
67
64
|
def self.check_cache
|
68
65
|
if @options.info[:cache]
|
69
66
|
@output += "\n"
|
70
|
-
printline( '
|
71
|
-
printline( '
|
72
|
-
printline( '
|
67
|
+
printline( 'Cache development', :cyan, grep( FILES[:conf_env_dev], PATTERNS[:cache] ) )
|
68
|
+
printline( 'Cache staging ', :yellow, grep( FILES[:conf_env_stag], PATTERNS[:cache] ) )
|
69
|
+
printline( 'Cache production ', :red, grep( FILES[:conf_env_prod], PATTERNS[:cache] ) )
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
73
|
def self.check_database
|
77
|
-
if File.exist? FILES[:conf_db]
|
74
|
+
if @options.info[:database] && File.exist?( FILES[:conf_db] )
|
75
|
+
@output += "\n"
|
78
76
|
if @options[:verbose]
|
79
77
|
printline FILES[:conf_db], {}, ' '
|
80
78
|
@output += cat FILES[:conf_db]
|
@@ -82,8 +80,21 @@ module PinfoRails
|
|
82
80
|
content = YAML.load_file( FILES[:conf_db] ) rescue nil
|
83
81
|
if content.nil?
|
84
82
|
@output += "ERR: invalid YAML file: #{FILES[:conf_db]}"
|
85
|
-
|
86
|
-
|
83
|
+
else
|
84
|
+
content.sort.each do |env, _data|
|
85
|
+
color =
|
86
|
+
case env
|
87
|
+
when 'staging'
|
88
|
+
:yellow
|
89
|
+
when 'production'
|
90
|
+
:red
|
91
|
+
when 'test'
|
92
|
+
:blue
|
93
|
+
else
|
94
|
+
:cyan
|
95
|
+
end
|
96
|
+
printline( "Database #{env}", color, param( 'adapter', content[env]['adapter'] ), param( 'host', content[env]['host'] ), param( 'database', content[env]['database'] ), param( 'username', content[env]['username'] ), param( 'password', content[env]['password'] ) )
|
97
|
+
end
|
87
98
|
end
|
88
99
|
end
|
89
100
|
end
|
@@ -106,7 +117,7 @@ module PinfoRails
|
|
106
117
|
|
107
118
|
def self.check_requirements
|
108
119
|
@options.reqs.split( ',' ).each do |req|
|
109
|
-
printline( 'Required', :
|
120
|
+
printline( 'Required', :green, grep( FILES[:gemfile], Regexp.new( "['|\"][^'\"]*#{req}[^'\"]*['|\"]" ) ) )
|
110
121
|
end
|
111
122
|
end
|
112
123
|
|
@@ -125,17 +136,23 @@ module PinfoRails
|
|
125
136
|
lines = []
|
126
137
|
if File.exist? file
|
127
138
|
File.read( file ).each_line do |line|
|
128
|
-
lines.push( Regexp.last_match ) if !( line.strip =~ /^#.*$/ ) && line =~ expression
|
139
|
+
lines.push( Regexp.last_match.to_s.strip ) if !( line.strip =~ /^#.*$/ ) && line =~ expression
|
129
140
|
end
|
130
141
|
end
|
131
142
|
( lines.length > 1 ? "\n " : '' ) + lines.join( "\n " )
|
132
143
|
end
|
133
144
|
|
145
|
+
def self.param( k, v )
|
146
|
+
!v.nil? ? ( k + ' = ' + v ) : ''
|
147
|
+
end
|
148
|
+
|
134
149
|
def self.printline( intro, styles, *strings )
|
135
|
-
|
150
|
+
strings = strings.reject { |s| s.nil? || s.empty? }
|
151
|
+
cnt = strings.length
|
136
152
|
return unless cnt > 0
|
137
153
|
@output += '- ' + intro + ': '
|
138
|
-
@output +=
|
154
|
+
# @output += "\n " if cnt > 1
|
155
|
+
@output += @options[:styles] ? strings.map( &:to_s ).join( '; ' ).colorize( styles ) : strings.map( &:to_s ).join( '; ' )
|
139
156
|
@output += "\n"
|
140
157
|
end
|
141
158
|
|
@@ -150,6 +167,7 @@ module PinfoRails
|
|
150
167
|
options.styles = true
|
151
168
|
options.verbose = false
|
152
169
|
options.info = {
|
170
|
+
database: true,
|
153
171
|
cache: true,
|
154
172
|
deploy: true
|
155
173
|
}
|
@@ -157,33 +175,32 @@ module PinfoRails
|
|
157
175
|
begin
|
158
176
|
opt_parser = OptionParser.new do |opts|
|
159
177
|
opts.banner = 'Usage: pinfo [options]'
|
160
|
-
|
161
178
|
opts.separator ''
|
162
179
|
opts.separator 'Specific options:'
|
163
|
-
|
164
180
|
opts.on('-cCONF', '--config=CONF', 'Config file') do |v|
|
165
181
|
options.conf = v
|
166
182
|
end
|
167
183
|
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
168
184
|
options.verbose = v
|
169
185
|
end
|
170
|
-
opts.separator ''
|
171
|
-
opts.on('-s', '--[no-]styles', 'With styles and colors (default)') do |v|
|
172
|
-
options.styles = v
|
173
|
-
end
|
174
186
|
opts.on('-rREQS', '--required=REQS', 'Search for specific gems') do |v|
|
175
187
|
options.reqs = v
|
176
188
|
end
|
189
|
+
opts.on('-s', '--[no-]styles', 'With styles and colors (default)') do |v|
|
190
|
+
options.styles = v
|
191
|
+
end
|
192
|
+
opts.separator ''
|
177
193
|
opts.on('--[no-]cache', 'Show cache info') do |v|
|
178
194
|
options.info[:cache] = v
|
179
195
|
end
|
196
|
+
opts.on('--[no-]database', 'Show database info') do |v|
|
197
|
+
options.info[:database] = v
|
198
|
+
end
|
180
199
|
opts.on('--[no-]deploy', 'Show deploy info') do |v|
|
181
200
|
options.info[:deploy] = v
|
182
201
|
end
|
183
|
-
|
184
202
|
opts.separator ''
|
185
203
|
opts.separator 'Common options:'
|
186
|
-
|
187
204
|
opts.on_tail('-h', '--help', 'Show this message') do
|
188
205
|
puts opts
|
189
206
|
exit
|
@@ -203,7 +220,10 @@ module PinfoRails
|
|
203
220
|
opt_parser.parse!( lines )
|
204
221
|
end
|
205
222
|
opt_parser.parse!( args )
|
206
|
-
rescue
|
223
|
+
rescue OptionParser::MissingArgument => e
|
224
|
+
puts 'ERR: ' + e.message
|
225
|
+
exit
|
226
|
+
rescue OptionParser::InvalidOption => e
|
207
227
|
puts 'ERR: ' + e.message
|
208
228
|
exit
|
209
229
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinfo-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -33,7 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- bin/pinfo
|
35
35
|
- lib/pinfo-rails.rb
|
36
|
-
homepage:
|
36
|
+
homepage: https://github.com/blocknotes/pinfo-rails
|
37
37
|
licenses:
|
38
38
|
- MIT
|
39
39
|
metadata: {}
|