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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDllMzI2MTRhZGNjZDM4Nzk0OTRjOTg2ZTE0YTUyOTcyOTIzM2U3OA==
4
+ YTdjYjQ4MDJkYjc5ZTJlM2ViYzM3YzE2NjU3NDg3MmE1NzBmNDExZA==
5
5
  data.tar.gz: !binary |-
6
- YTFmMmQxNTgwODY2OTIxNDI3MTFlOTA4N2EzOTQwNjhkNjRjODk2Mw==
6
+ YTBiZmUzZmY3NDdmYjEwODlkNWQxMTU4YmI2NTAxYjI0YmIwOWMwMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Zjk1M2EwMzRlZDdjOTNjOTgxZmYzY2I5YzU0MTdjMTM2NDA1NjY0YWIyZTA4
10
- NjNiYmMxNTM2Mjg0MmIwMWE5ZDlmNDg0YTgzYjgxYjU1MTNiNWY0NzdmZTkw
11
- ODg5MTMxNDhiODM0NjljYmExNGRmMDBhM2I5NmI3OGJiMmJiMWY=
9
+ MTRlNzUzZjhmOWM4Nzc5MjdiMzVjYTk3NWU4M2NlZDYyNTU5YzBhODY3ODU1
10
+ MzY5YjQ2ODIzMmNlZWNlOWU0MzFmMmExMmFkNzc0ZGUwMmRkMzU3ZjU4N2E3
11
+ MGFmNDE0MmM2YzRjMjJkNzBhNTg0NjY2ZWU3OTA2ODE2MjcxNWM=
12
12
  data.tar.gz: !binary |-
13
- NTYwOGY2MjkxYzljZDcxYjQ2YmQ5OTAxMjZmMDUzYjc1YjI2ZjZiMWFhZWYw
14
- MDI4YjRmZmViODc3NDBjZDlhZTFmNDlmMzdmYjNiYmE2YTNlZGQwM2QzNjk3
15
- MmJlMWIzMTFiMzQyNGI3OGUyY2IzMjU2ZDU5OTQzOWZjYjQ5YzI=
13
+ ZTc3ZDdkMTIzZWNiNDU5MGMxOGQ0M2ZlYzVjNTQ3NWIzOWRlY2MxZGNiMDcx
14
+ YzQ2MTdlMTQwYWRmNTVlODQ4NDYzMTAxZWI0MzYwY2VhNTU4YTQ1NmFhYzkw
15
+ NzFiNDE3MzQ2MGM1ZTg0OTg0OTM4OGUzNmY1NDNmODBmZDA4ODg=
@@ -1,35 +1,81 @@
1
1
  class ActiveRecord::Base
2
2
  def self.ls(*attrs)
3
- attrs.map!(&:to_s)
4
- attrs.unshift('id')
5
- attrs << 'name' if self.attribute_names.include?('name')
6
- attrs << 'title' if self.attribute_names.include?('title')
7
- attrs.uniq!
8
- lengths = {}
9
- records = self.all
10
- if records.count < 1
11
- return
12
- end
13
- records.each do |r|
14
- attrs.each do |a|
15
- val = r
16
- a.split('.').map{|path| val = val.send(path)}
17
- len = val.to_s.length
18
- lengths[a] ||= a.length
19
- lengths[a] = [lengths[a], len].max
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
- out = [attrs.map{|a| a.rjust(lengths[a]+1)}.join]
23
- out += records.map { |r|
24
- line = ""
25
- attrs.each do |a|
26
- val = r
27
- a.split('.').map{|path| val = val.send(path)}
28
- line << val.to_s.rjust(lengths[a]+1)
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
- line
31
- }
32
- out.each{|s| puts s }
33
- out.length - 1
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
@@ -1,3 +1,3 @@
1
1
  module Raicoto
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-03-10 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler