pinfo-rails 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/pinfo +5 -0
- data/lib/pinfo-rails.rb +213 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc5f098badf2e938684903e92faa611b7ba63a50
|
4
|
+
data.tar.gz: 85eedea1f0dcc2bfa9538f143b76f50b5c030c4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: def8e089d956281cd0a60eace8194f23cba99ced65dea406f2a05b7f1587e8fedf0b409ae7afd90dd544c6c947ff3fcff8a19708fc52aa801912e324ce168a55
|
7
|
+
data.tar.gz: aa62b796e59a7c8d87d5ea43ec826726e85db61d2f3e02b4e15202e4f48eef3b5ec1f7559b53de3b2c11b98a54b2a2f3940a2985833c41d798262d6b5fc21b2b
|
data/bin/pinfo
ADDED
data/lib/pinfo-rails.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'colorize'
|
3
|
+
require 'optparse'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module PinfoRails
|
8
|
+
NAME = 'pinfo-rails'.freeze
|
9
|
+
DATE = '2016-10-08'.freeze
|
10
|
+
INFO = 'Rails project info'.freeze
|
11
|
+
DESC = 'A gem to collect informations from a Rails project'.freeze
|
12
|
+
AUTHORS = [ [ 'Mattia Roccoberton', 'mat@blocknot.es', 'http://blocknot.es' ] ].freeze
|
13
|
+
VERSION = [ 0, 1, 2 ].freeze
|
14
|
+
|
15
|
+
FILES = {
|
16
|
+
conf_db: 'config/database.yml',
|
17
|
+
conf_env_dev: 'config/environments/development.rb',
|
18
|
+
conf_env_stag: 'config/environments/staging.rb',
|
19
|
+
conf_env_prod: 'config/environments/production.rb',
|
20
|
+
conf_dep: 'config/deploy.rb',
|
21
|
+
conf_dep_stag: 'config/deploy/staging.rb',
|
22
|
+
conf_dep_prod: 'config/deploy/production.rb',
|
23
|
+
gemfile: 'Gemfile'
|
24
|
+
}.freeze
|
25
|
+
PATTERNS = {
|
26
|
+
cache: /config.cache_classes.*/,
|
27
|
+
deploy_info: /branch\s*,.*|user\s*,.*|domain\s*,.*|server[^,]+/,
|
28
|
+
deploy_tool: /'capistrano'|"capistrano|'capistrano-rails'|"capistrano-rails"|'mina'|"mina"/,
|
29
|
+
deploy_user: /user.*/,
|
30
|
+
rails: /'rails'.*|"rails".*/
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
# pinfo-rails: A gem to collect informations from a Rails project
|
34
|
+
class PinfoRails
|
35
|
+
# main method
|
36
|
+
def self.info( args )
|
37
|
+
@conf = {}
|
38
|
+
@options = optparse( args )
|
39
|
+
|
40
|
+
@output = ''
|
41
|
+
@output += "[verbose mode]\n" if @options[:verbose]
|
42
|
+
if @options[:conf]
|
43
|
+
@output += "[with config: #{@options[:conf]}]\n"
|
44
|
+
if File.exist? @options[:conf]
|
45
|
+
lines = File.read( @options[:conf] ).split( "\n" ).reject { |l| l =~ /^\s*$|^\s*#.*$/ }.map { |l| "--#{l.strip}" }
|
46
|
+
@options = optparse( lines )
|
47
|
+
else
|
48
|
+
puts 'ERR: file not found'
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Ruby version
|
54
|
+
printline( 'Ruby', { color: :green, mode: :bold }, RUBY_VERSION, @options[:verbose] ? 'p' + RUBY_PATCHLEVEL.to_s : nil )
|
55
|
+
# Rails version
|
56
|
+
printline( 'Rails', { color: :green, mode: :bold }, grep( FILES[:gemfile], PATTERNS[:rails] ) )
|
57
|
+
check_database
|
58
|
+
check_requirements
|
59
|
+
check_cache
|
60
|
+
check_deploy
|
61
|
+
|
62
|
+
@output
|
63
|
+
end
|
64
|
+
|
65
|
+
# support methods
|
66
|
+
|
67
|
+
def self.check_cache
|
68
|
+
if @options.info[:cache]
|
69
|
+
@output += "\n"
|
70
|
+
printline( 'Development', :cyan, grep( FILES[:conf_env_dev], PATTERNS[:cache] ) )
|
71
|
+
printline( 'Staging ', :yellow, grep( FILES[:conf_env_stag], PATTERNS[:cache] ) )
|
72
|
+
printline( 'Production ', :red, grep( FILES[:conf_env_prod], PATTERNS[:cache] ) )
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.check_database
|
77
|
+
if File.exist? FILES[:conf_db]
|
78
|
+
if @options[:verbose]
|
79
|
+
printline FILES[:conf_db], {}, ' '
|
80
|
+
@output += cat FILES[:conf_db]
|
81
|
+
else
|
82
|
+
content = YAML.load_file( FILES[:conf_db] ) rescue nil
|
83
|
+
if content.nil?
|
84
|
+
@output += "ERR: invalid YAML file: #{FILES[:conf_db]}"
|
85
|
+
elsif content['development']
|
86
|
+
printline( 'DB (development)', :cyan, content['development']['adapter'], content['development']['database'] )
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.check_deploy
|
93
|
+
if @options.info[:deploy]
|
94
|
+
@output += "\n"
|
95
|
+
printline( 'Deploy tool', { color: :green, mode: :bold }, grep( FILES[:gemfile], PATTERNS[:deploy_tool] ) )
|
96
|
+
if @options[:verbose]
|
97
|
+
printline FILES[:conf_dep], {}, ' '
|
98
|
+
@output += cat FILES[:conf_dep]
|
99
|
+
else
|
100
|
+
printline( 'Deploy user', :green, grep( FILES[:conf_dep], PATTERNS[:deploy_user] ) )
|
101
|
+
end
|
102
|
+
printline( 'Staging ', :yellow, grep( FILES[:conf_dep_stag], PATTERNS[:deploy_info] ) )
|
103
|
+
printline( 'Production ', :red, grep( FILES[:conf_dep_prod], PATTERNS[:deploy_info] ) )
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.check_requirements
|
108
|
+
@options.reqs.split( ',' ).each do |req|
|
109
|
+
printline( 'Required', :blue, grep( FILES[:gemfile], Regexp.new( "['|\"][^'\"]*#{req}[^'\"]*['|\"]" ) ) )
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.cat( file )
|
114
|
+
lines = []
|
115
|
+
if File.exist? file
|
116
|
+
File.read( file ).each_line do |line|
|
117
|
+
lines.push( line.rstrip ) unless line.strip =~ /^$|^#.*$/
|
118
|
+
end
|
119
|
+
lines.push( '' )
|
120
|
+
end
|
121
|
+
lines.join( "\n" )
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.grep( file, expression )
|
125
|
+
lines = []
|
126
|
+
if File.exist? file
|
127
|
+
File.read( file ).each_line do |line|
|
128
|
+
lines.push( Regexp.last_match ) if !( line.strip =~ /^#.*$/ ) && line =~ expression
|
129
|
+
end
|
130
|
+
end
|
131
|
+
( lines.length > 1 ? "\n " : '' ) + lines.join( "\n " )
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.printline( intro, styles, *strings )
|
135
|
+
cnt = strings.reject { |s| s.nil? || s.empty? }.length
|
136
|
+
return unless cnt > 0
|
137
|
+
@output += '- ' + intro + ': '
|
138
|
+
@output += @options[:styles] ? strings.compact.map( &:to_s ).join( ', ' ).colorize( styles ) : strings.compact.map( &:to_s ).join( ', ' )
|
139
|
+
@output += "\n"
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.optparse( args )
|
143
|
+
options = OpenStruct.new
|
144
|
+
options.library = []
|
145
|
+
options.inplace = false
|
146
|
+
options.encoding = 'utf8'
|
147
|
+
options.transfer_type = :auto
|
148
|
+
options.conf = nil
|
149
|
+
options.reqs = ''
|
150
|
+
options.styles = true
|
151
|
+
options.verbose = false
|
152
|
+
options.info = {
|
153
|
+
cache: true,
|
154
|
+
deploy: true
|
155
|
+
}
|
156
|
+
|
157
|
+
begin
|
158
|
+
opt_parser = OptionParser.new do |opts|
|
159
|
+
opts.banner = 'Usage: pinfo [options]'
|
160
|
+
|
161
|
+
opts.separator ''
|
162
|
+
opts.separator 'Specific options:'
|
163
|
+
|
164
|
+
opts.on('-cCONF', '--config=CONF', 'Config file') do |v|
|
165
|
+
options.conf = v
|
166
|
+
end
|
167
|
+
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
168
|
+
options.verbose = v
|
169
|
+
end
|
170
|
+
opts.separator ''
|
171
|
+
opts.on('-s', '--[no-]styles', 'With styles and colors (default)') do |v|
|
172
|
+
options.styles = v
|
173
|
+
end
|
174
|
+
opts.on('-rREQS', '--required=REQS', 'Search for specific gems') do |v|
|
175
|
+
options.reqs = v
|
176
|
+
end
|
177
|
+
opts.on('--[no-]cache', 'Show cache info') do |v|
|
178
|
+
options.info[:cache] = v
|
179
|
+
end
|
180
|
+
opts.on('--[no-]deploy', 'Show deploy info') do |v|
|
181
|
+
options.info[:deploy] = v
|
182
|
+
end
|
183
|
+
|
184
|
+
opts.separator ''
|
185
|
+
opts.separator 'Common options:'
|
186
|
+
|
187
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
188
|
+
puts opts
|
189
|
+
exit
|
190
|
+
end
|
191
|
+
opts.on_tail('--about', 'Show about') do
|
192
|
+
puts INFO + ' v' + VERSION.join('.') + "\n" + DESC + "\nby " + AUTHORS.first.join( ', ' )
|
193
|
+
exit
|
194
|
+
end
|
195
|
+
opts.on_tail('--version', 'Show version') do
|
196
|
+
puts VERSION.join('.')
|
197
|
+
exit
|
198
|
+
end
|
199
|
+
end
|
200
|
+
if File.exist? File.expand_path '~/.pinfo-rails.conf'
|
201
|
+
# global configuration
|
202
|
+
lines = File.read( File.expand_path( '~/.pinfo-rails.conf' ) ).split( "\n" ).reject { |l| l =~ /^\s*$|^\s*#.*$/ }.map { |l| "--#{l.strip}" }
|
203
|
+
opt_parser.parse!( lines )
|
204
|
+
end
|
205
|
+
opt_parser.parse!( args )
|
206
|
+
rescue Exception => e
|
207
|
+
puts 'ERR: ' + e.message
|
208
|
+
exit
|
209
|
+
end
|
210
|
+
options
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pinfo-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattia Roccoberton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.0
|
27
|
+
description: A gem to collect informations from a Rails project
|
28
|
+
email: mat@blocknot.es
|
29
|
+
executables:
|
30
|
+
- pinfo
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/pinfo
|
35
|
+
- lib/pinfo-rails.rb
|
36
|
+
homepage: http://rubygems.org/gems/pinfo-rails
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.4.8
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Rails project info
|
60
|
+
test_files: []
|