arspy 0.0.4 → 0.0.5
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.
- data/.gitignore +2 -0
- data/Rakefile +2 -0
- data/lib/arspy/class_extensions.rb +2 -0
- data/lib/arspy/delegators/active_record_extensions.rb +2 -1
- data/lib/arspy/delegators/array_extensions.rb +5 -2
- data/lib/arspy/delegators/association_collection_extensions.rb +10 -6
- data/lib/arspy/delegators/null_extensions.rb +1 -0
- data/lib/arspy/operators.rb +23 -6
- data/lib/arspy.rb +3 -0
- metadata +18 -5
data/.gitignore
CHANGED
data/Rakefile
CHANGED
|
@@ -11,6 +11,8 @@ spec = Gem::Specification.new do |s|
|
|
|
11
11
|
s.required_ruby_version = '>= 1.8.7'
|
|
12
12
|
s.description = 'Active Record Spy'
|
|
13
13
|
s.summary = 'Rails console command line tool for browsing and inspecting the structure, associations and data of an ActiveRecord data model.'
|
|
14
|
+
|
|
15
|
+
s.add_dependency('awesome_print', '>= 0.1.1')
|
|
14
16
|
|
|
15
17
|
exclude_folders = '' # 'spec/rails/{doc,lib,log,nbproject,tmp,vendor,test}'
|
|
16
18
|
exclude_files = [] # FileList['**/*.log'] + FileList[exclude_folders+'/**/*'] + FileList[exclude_folders]
|
|
@@ -4,6 +4,8 @@ module Arspy
|
|
|
4
4
|
module Base
|
|
5
5
|
def la; Arspy::Operators.list_associations(self); end
|
|
6
6
|
def lf; Arspy::Operators.list_fields(self); end
|
|
7
|
+
def pr; Arspy::Operators.awesome_print(self); end
|
|
8
|
+
def ap(opts={}); Arspy::Operators.awesome_print(self, opts); end
|
|
7
9
|
end
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
module Arspy
|
|
2
2
|
module Delegators
|
|
3
3
|
module ActiveRecordExtensions
|
|
4
|
-
def pr(*args); Arspy::Operators.print_object(self, *args); end
|
|
5
4
|
def la; Arspy::Operators.list_associations(self.class); end
|
|
6
5
|
def lf; Arspy::Operators.list_fields(self.class); end
|
|
6
|
+
def pr(*args); Arspy::Operators.print_object(self, *args); end
|
|
7
|
+
def ap(opts={}); Arspy::Operators.awesome_print(self, opts); end
|
|
7
8
|
end
|
|
8
9
|
end
|
|
9
10
|
end
|
|
@@ -14,10 +14,13 @@ module Arspy
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def la
|
|
17
|
-
Arspy::Operators.list_associations(self.first
|
|
17
|
+
Arspy::Operators.list_associations(self.first) unless self.emtpy?
|
|
18
18
|
end
|
|
19
19
|
def lf
|
|
20
|
-
Arspy::Operators.list_fields(self.first
|
|
20
|
+
Arspy::Operators.list_fields(self.first) unless self.empty?
|
|
21
|
+
end
|
|
22
|
+
def ap(opts={})
|
|
23
|
+
Arspy::Operators.awesome_print(self, opts={}) unless self.empty?
|
|
21
24
|
end
|
|
22
25
|
def pr(*args)
|
|
23
26
|
Arspy::Operators.print_array(self, *args)
|
|
@@ -9,17 +9,21 @@ module Arspy
|
|
|
9
9
|
result
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
-
def pr(*args)
|
|
13
|
-
load_target unless loaded?
|
|
14
|
-
Arspy::Operators.print_array(@target, *args)
|
|
15
|
-
end
|
|
16
12
|
def la
|
|
17
13
|
load_target unless loaded?
|
|
18
|
-
Arspy::Operators.list_associations(@target.first
|
|
14
|
+
Arspy::Operators.list_associations(@target.first) unless @target.emtpy?
|
|
19
15
|
end
|
|
20
16
|
def lf
|
|
21
17
|
load_target unless loaded?
|
|
22
|
-
Arspy::Operators.list_fields(@target.first
|
|
18
|
+
Arspy::Operators.list_fields(@target.first) unless @target.empty?
|
|
19
|
+
end
|
|
20
|
+
def pr(*args)
|
|
21
|
+
load_target unless loaded?
|
|
22
|
+
Arspy::Operators.print_array(@target, *args)
|
|
23
|
+
end
|
|
24
|
+
def ap(opts={})
|
|
25
|
+
load_target unless loaded?
|
|
26
|
+
Arspy::Operators.awesome_print(@target, opts) unless @target.empty?
|
|
23
27
|
end
|
|
24
28
|
def wi(*args)
|
|
25
29
|
load_target unless loaded?
|
data/lib/arspy/operators.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module Arspy
|
|
2
2
|
module Operators
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
def self.list_associations(klass_or_object)
|
|
5
|
+
active_record_klass = klass_or_object.is_a?(Class) ? klass_or_object : klass_or_object.class
|
|
6
|
+
return unless active_record_klass.ancestors.include?(ActiveRecord::Base)
|
|
4
7
|
counts = {}
|
|
5
8
|
rows = active_record_klass.reflect_on_all_associations.map do |assoc|
|
|
6
9
|
counts[assoc.macro] ||= 0
|
|
@@ -12,7 +15,9 @@ module Arspy
|
|
|
12
15
|
"Total: #{counts.inject(0){|sum, count| sum+count.last}} (" + counts.map{|count| "#{count.last} #{count.first}" }.join(', ') + ")"
|
|
13
16
|
end
|
|
14
17
|
|
|
15
|
-
def self.list_fields(
|
|
18
|
+
def self.list_fields(klass_or_object)
|
|
19
|
+
active_record_klass = klass_or_object.is_a?(Class) ? klass_or_object : klass_or_object.class
|
|
20
|
+
return unless active_record_klass.ancestors.include?(ActiveRecord::Base)
|
|
16
21
|
rows = active_record_klass.columns.map do |column|
|
|
17
22
|
self.format_column_field(column)
|
|
18
23
|
end
|
|
@@ -21,6 +26,11 @@ module Arspy
|
|
|
21
26
|
"Total #{active_record_klass.columns.size} field#{active_record_klass.columns.size == 1 ? '' : 's'}"
|
|
22
27
|
end
|
|
23
28
|
|
|
29
|
+
def self.awesome_print(klass_object_or_array, options={})
|
|
30
|
+
AwesomePrint.new(options).puts klass_object_or_array
|
|
31
|
+
nil
|
|
32
|
+
end
|
|
33
|
+
|
|
24
34
|
def self.format_column_association(assoc)
|
|
25
35
|
select_options = assoc.options.select{|k,v| [:through, :as, :polymorphic].include?(k)}
|
|
26
36
|
[assoc.name.to_s, assoc.macro.to_s, "(#{assoc.options[:class_name] || assoc.name.to_s.singularize.camelize})", select_options.empty? ? '' : Hash[*select_options.flatten].inspect]
|
|
@@ -30,7 +40,14 @@ module Arspy
|
|
|
30
40
|
end
|
|
31
41
|
|
|
32
42
|
def self.print_array(array, *args)
|
|
33
|
-
|
|
43
|
+
if args.empty?
|
|
44
|
+
case array.first
|
|
45
|
+
when ActiveRecord::Base then AwesomePrint.new.puts(array)
|
|
46
|
+
else
|
|
47
|
+
array.each{|element| puts element}
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
#array.each{|element| puts element.is_a?(String) ? element : element.inspect } if args.empty?
|
|
34
51
|
self.print_matrix(
|
|
35
52
|
array.map do |obj|
|
|
36
53
|
args.map do |arg|
|
|
@@ -46,8 +63,8 @@ module Arspy
|
|
|
46
63
|
end
|
|
47
64
|
|
|
48
65
|
def self.print_object(object, *args)
|
|
49
|
-
print_matrix([args.map{|arg| object[arg]}])
|
|
50
|
-
puts(object
|
|
66
|
+
print_matrix([args.map{|arg| object[arg]}]) unless args.empty?
|
|
67
|
+
AwesomePrint.new.puts(object) if args.empty?
|
|
51
68
|
nil
|
|
52
69
|
end
|
|
53
70
|
def self.test_object(obj, args)
|
|
@@ -127,7 +144,7 @@ module Arspy
|
|
|
127
144
|
list[desc[:abbr]] = desc
|
|
128
145
|
end
|
|
129
146
|
end
|
|
130
|
-
descriptors.reject!{|desc| ambiguities.map{|
|
|
147
|
+
descriptors.reject!{|desc| ambiguities.map{|hash| hash.first}.include?(desc[:abbr])}
|
|
131
148
|
ambiguities
|
|
132
149
|
end
|
|
133
150
|
def self.abbreviate_method_name(method_name)
|
data/lib/arspy.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'rubygems'
|
|
1
2
|
raise 'Arspy only runs in an ActiveRecord environment' unless defined?(ActiveRecord::Base)
|
|
2
3
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
|
|
3
4
|
|
|
@@ -6,6 +7,8 @@ require 'meta_programming'
|
|
|
6
7
|
require 'arspy/operators'
|
|
7
8
|
require 'arspy/delegators'
|
|
8
9
|
require 'arspy/class_extensions'
|
|
10
|
+
gem 'awesome_print', ">= 0.1.1"
|
|
11
|
+
require 'ap'
|
|
9
12
|
|
|
10
13
|
module Arspy
|
|
11
14
|
def self.included(base)
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
8
|
+
- 5
|
|
9
|
+
version: 0.0.5
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Jeff Patmon
|
|
@@ -14,10 +14,23 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-04-
|
|
17
|
+
date: 2010-04-05 00:00:00 -07:00
|
|
18
18
|
default_executable:
|
|
19
|
-
dependencies:
|
|
20
|
-
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: awesome_print
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 0
|
|
29
|
+
- 1
|
|
30
|
+
- 1
|
|
31
|
+
version: 0.1.1
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
21
34
|
description: Active Record Spy
|
|
22
35
|
email: jpatmon@gmail.com
|
|
23
36
|
executables: []
|