raicoto 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTNkMjEzYTI5YWIxNmI2NGY2ZDZkY2RiZTRhZmZlYzQwNGQyM2Y4MQ==
5
- data.tar.gz: !binary |-
6
- OWVkMGQxZDc2M2UxYTcxMzkwODQ0YmIwZDdiZDBhYzIwNDFlYmFhZg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTI3NmFhNTA0YmVlMGUxNTYyOTUyZDZlZGI2ZjVkYjc4ZTA1NDA3MmViNmVj
10
- ZjA4ZWI0OTQ4N2M0NGNiNzM5ZjU5OTBiZjJkMmU5M2M5OGY2ZWI0Mzg4OTQ1
11
- YTY1ZTNlZTU3MGRhN2I3NWFmZWRhMzg3ZDg3YzJkZjdmMmUyODc=
12
- data.tar.gz: !binary |-
13
- ZmE4ZTI4NjljM2IwNWNmN2MyNzc4NDc0MjM0YTlkYzdlZjZjNjc5NGQxZTJj
14
- OWEzNGFjOWY3YjhkYmI4MmNkZjVjZDYzYTkyZjQ1MjU2MjRiMjA5YmZjZTFh
15
- YjFjOGZiYTA3ZjExNGM2M2NjY2YzYjI3MTBiYmVhNDIwZTk4NDU=
2
+ SHA1:
3
+ metadata.gz: 1c331e96d238e14af25cb75f653102e5f116d806
4
+ data.tar.gz: b444cdb3e01ee46989f623e5e63074420f4e021f
5
+ SHA512:
6
+ metadata.gz: 444f30e987f03a2e32e10fb408d1d4e621938f304b206a4436546553541b28dbffd2ec9a5b59f9f51184f5556f338d9d072176bca049e914e164096ec114255f
7
+ data.tar.gz: 1cbf80383c8e497bfb084ce99d8eb1bd4648d1492e1bd8c7af8f73ee85a928dab6854fb273de9827d8af3aa1cd3ffd8d1cc8214bdae4d3d99aa3c533e3a8df7c
data/lib/raicoto.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "raicoto/version"
2
+ require 'raicoto/inspection'
2
3
 
3
4
  if defined?(Rails)
4
5
  require 'raicoto/railtie'
5
- end
6
+ end
7
+
8
+ require 'raicoto/array/inspection'
@@ -1,39 +1,7 @@
1
1
  class ActiveRecord::Base
2
- def self.ls(*attrs)
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
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
36
- end
2
+ extend Raicoto::Inspection
3
+ def self._all_for_ls
4
+ self.all
37
5
  end
38
6
 
39
7
  def self.map(&block)
@@ -0,0 +1,59 @@
1
+ class ::Array
2
+ include Raicoto::Inspection
3
+
4
+ def ls(*attrs)
5
+ ActiveRecord.without_logging do
6
+ attrs.map!(&:to_s)
7
+ attrs.unshift('id')
8
+ attrs << 'name' if self._attribute_names.include?('name')
9
+ attrs << 'title' if self._attribute_names.include?('title')
10
+ attrs.uniq!
11
+ lengths = {}
12
+ records = self._all_for_ls
13
+ if records.count < 1
14
+ puts "No Records."
15
+ return
16
+ end
17
+ records.each do |r|
18
+ attrs.each do |a|
19
+ val = r
20
+ a.split('.').map{|path| val = val.send(path)}
21
+ len = val.to_s.length
22
+ lengths[a] ||= a.length
23
+ lengths[a] = [lengths[a], len].max
24
+ end
25
+ end
26
+ out = [attrs.map{|a| a.rjust(lengths[a]+1)}.join]
27
+ out += records.map { |r|
28
+ line = ""
29
+ attrs.each do |a|
30
+ val = r
31
+ a.split('.').map{|path| val = val.send(path)}
32
+ line << val.to_s.rjust(lengths[a]+1)
33
+ end
34
+ line
35
+ }
36
+ out.each{|s| puts s }
37
+ out.length - 1
38
+ end
39
+ end
40
+
41
+ def _all_for_ls
42
+ self
43
+ end
44
+
45
+ def _attribute_names
46
+ return [] if empty?
47
+ case true
48
+ when first.respond_to?(:attribute_names)
49
+ first.attribute_names
50
+ when first.respond_to?(:attributes)
51
+ first.attributes.keys
52
+ when first.respond_to?(:keys)
53
+ first.keys
54
+ else
55
+ raise "don't know how to get attribute_names for #{first.inspect}"
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ module Raicoto
2
+ module Inspection
3
+ def ls(*attrs)
4
+ ActiveRecord.without_logging do
5
+ attrs.map!(&:to_s)
6
+ attrs.unshift('id')
7
+ attrs << 'name' if self.attribute_names.include?('name')
8
+ attrs << 'title' if self.attribute_names.include?('title')
9
+ attrs.uniq!
10
+ lengths = {}
11
+ records = self.all
12
+ if records.count < 1
13
+ puts "No Records."
14
+ return
15
+ end
16
+ records.each do |r|
17
+ attrs.each do |a|
18
+ val = r
19
+ a.split('.').map{|path| val = val.send(path)}
20
+ len = val.to_s.length
21
+ lengths[a] ||= a.length
22
+ lengths[a] = [lengths[a], len].max
23
+ end
24
+ end
25
+ out = [attrs.map{|a| a.rjust(lengths[a]+1)}.join]
26
+ out += records.map { |r|
27
+ line = ""
28
+ attrs.each do |a|
29
+ val = r
30
+ a.split('.').map{|path| val = val.send(path)}
31
+ line << val.to_s.rjust(lengths[a]+1)
32
+ end
33
+ line
34
+ }
35
+ out.each{|s| puts s }
36
+ out.length - 1
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Raicoto
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raicoto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Random assortment of rails console tools
@@ -45,13 +45,15 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/raicoto.rb
54
54
  - lib/raicoto/activerecord/inspection.rb
55
+ - lib/raicoto/array/inspection.rb
56
+ - lib/raicoto/inspection.rb
55
57
  - lib/raicoto/railtie.rb
56
58
  - lib/raicoto/version.rb
57
59
  - raicoto.gemspec
@@ -65,17 +67,17 @@ require_paths:
65
67
  - lib
66
68
  required_ruby_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
- - - ! '>='
70
+ - - ">="
69
71
  - !ruby/object:Gem::Version
70
72
  version: '0'
71
73
  required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements:
73
- - - ! '>='
75
+ - - ">="
74
76
  - !ruby/object:Gem::Version
75
77
  version: '0'
76
78
  requirements: []
77
79
  rubyforge_project:
78
- rubygems_version: 2.0.6
80
+ rubygems_version: 2.2.2
79
81
  signing_key:
80
82
  specification_version: 4
81
83
  summary: Random assortment of rails console tools