raicoto 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/raicoto/activerecord/inspection.rb +74 -28
- data/lib/raicoto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTdjYjQ4MDJkYjc5ZTJlM2ViYzM3YzE2NjU3NDg3MmE1NzBmNDExZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTBiZmUzZmY3NDdmYjEwODlkNWQxMTU4YmI2NTAxYjI0YmIwOWMwMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTRlNzUzZjhmOWM4Nzc5MjdiMzVjYTk3NWU4M2NlZDYyNTU5YzBhODY3ODU1
|
10
|
+
MzY5YjQ2ODIzMmNlZWNlOWU0MzFmMmExMmFkNzc0ZGUwMmRkMzU3ZjU4N2E3
|
11
|
+
MGFmNDE0MmM2YzRjMjJkNzBhNTg0NjY2ZWU3OTA2ODE2MjcxNWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTc3ZDdkMTIzZWNiNDU5MGMxOGQ0M2ZlYzVjNTQ3NWIzOWRlY2MxZGNiMDcx
|
14
|
+
YzQ2MTdlMTQwYWRmNTVlODQ4NDYzMTAxZWI0MzYwY2VhNTU4YTQ1NmFhYzkw
|
15
|
+
NzFiNDE3MzQ2MGM1ZTg0OTg0OTM4OGUzNmY1NDNmODBmZDA4ODg=
|
@@ -1,35 +1,81 @@
|
|
1
1
|
class ActiveRecord::Base
|
2
2
|
def self.ls(*attrs)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
ActiveRecord.without_logging do
|
4
|
+
attrs.map!(&:to_s)
|
5
|
+
attrs.unshift('id')
|
6
|
+
attrs << 'name' if self.attribute_names.include?('name')
|
7
|
+
attrs << 'title' if self.attribute_names.include?('title')
|
8
|
+
attrs.uniq!
|
9
|
+
lengths = {}
|
10
|
+
records = self.all
|
11
|
+
if records.count < 1
|
12
|
+
puts "No Records."
|
13
|
+
return
|
14
|
+
end
|
15
|
+
records.each do |r|
|
16
|
+
attrs.each do |a|
|
17
|
+
val = r
|
18
|
+
a.split('.').map{|path| val = val.send(path)}
|
19
|
+
len = val.to_s.length
|
20
|
+
lengths[a] ||= a.length
|
21
|
+
lengths[a] = [lengths[a], len].max
|
22
|
+
end
|
20
23
|
end
|
24
|
+
out = [attrs.map{|a| a.rjust(lengths[a]+1)}.join]
|
25
|
+
out += records.map { |r|
|
26
|
+
line = ""
|
27
|
+
attrs.each do |a|
|
28
|
+
val = r
|
29
|
+
a.split('.').map{|path| val = val.send(path)}
|
30
|
+
line << val.to_s.rjust(lengths[a]+1)
|
31
|
+
end
|
32
|
+
line
|
33
|
+
}
|
34
|
+
out.each{|s| puts s }
|
35
|
+
out.length - 1
|
21
36
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module ActiveRecord
|
41
|
+
def self.without_logging
|
42
|
+
old_logger = ActiveRecord::Base.logger
|
43
|
+
ActiveRecord::Base.logger = nil
|
44
|
+
result = yield
|
45
|
+
ActiveRecord::Base.logger = old_logger
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.counts
|
50
|
+
klasses = []
|
51
|
+
without_logging do
|
52
|
+
tables = ActiveRecord::Base.connection.tables
|
53
|
+
col = tables.map(&:length).max
|
54
|
+
out = "Current Record Counts\n"
|
55
|
+
out << ("-"*col)+"------\n"
|
56
|
+
total = 0
|
57
|
+
tables.each do |table|
|
58
|
+
next if table.match(/\Aschema_migrations\Z/)
|
59
|
+
begin
|
60
|
+
klass = table.singularize.camelize.constantize
|
61
|
+
klasses << klass
|
62
|
+
count = klass.count
|
63
|
+
total += count
|
64
|
+
out << "#{klass.name.ljust(col)} #{count.to_s.rjust(5)}"
|
65
|
+
out << "\n"
|
66
|
+
rescue
|
67
|
+
sql = "Select count(*) from #{table}"
|
68
|
+
result = ActiveRecord::Base.connection.execute(sql)
|
69
|
+
count = result.first['count']
|
70
|
+
total += count.to_i
|
71
|
+
out << ".#{table.ljust(col)} #{count.rjust(5)}"
|
72
|
+
out << "\n"
|
73
|
+
end
|
29
74
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
75
|
+
out << ("-"*col)+"------\n"
|
76
|
+
puts out
|
77
|
+
puts "#{total} records in #{tables.length} tables."
|
78
|
+
end
|
79
|
+
klasses
|
34
80
|
end
|
35
81
|
end
|
data/lib/raicoto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raicoto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|