arspy 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -0
- data/Rakefile +1 -1
- data/lib/arspy/class_extensions.rb +2 -2
- data/lib/arspy/delegators/active_record_extensions.rb +2 -2
- data/lib/arspy/delegators/array_extensions.rb +4 -4
- data/lib/arspy/delegators/association_collection_extensions.rb +4 -4
- data/lib/arspy/delegators/null_extensions.rb +2 -2
- data/lib/arspy/operators/abbreviations.rb +68 -0
- data/lib/arspy/operators/attribute_test/base.rb +11 -0
- data/lib/arspy/operators/attribute_test/float_test.rb +24 -0
- data/lib/arspy/operators/attribute_test/integer_test.rb +24 -0
- data/lib/arspy/operators/attribute_test/range_test.rb +24 -0
- data/lib/arspy/operators/attribute_test/regexp_test.rb +23 -0
- data/lib/arspy/operators/attribute_test/string_test.rb +23 -0
- data/lib/arspy/operators/attribute_test/unsupported_test.rb +17 -0
- data/lib/arspy/operators/attribute_test.rb +20 -0
- data/lib/arspy/operators/interpreter/abbreviated_association_interpreter.rb +22 -0
- data/lib/arspy/operators/interpreter/abbreviated_attribute_interpreter.rb +22 -0
- data/lib/arspy/operators/interpreter/association_interpreter.rb +18 -0
- data/lib/arspy/operators/interpreter/attribute_interpreter.rb +21 -0
- data/lib/arspy/operators/interpreter/base.rb +11 -0
- data/lib/arspy/operators/interpreter/method_interpreter.rb +14 -0
- data/lib/arspy/operators/interpreter/null_interpreter.rb +12 -0
- data/lib/arspy/operators/interpreter.rb +29 -0
- data/lib/arspy/operators/selector/attribute_selector.rb +33 -0
- data/lib/arspy/operators/selector/base.rb +12 -0
- data/lib/arspy/operators/selector/hash_selector.rb +30 -0
- data/lib/arspy/operators/selector/integer_selector.rb +17 -0
- data/lib/arspy/operators/selector/range_selector.rb +17 -0
- data/lib/arspy/operators/selector/string_selector.rb +14 -0
- data/lib/arspy/operators/selector/unsupported_selector.rb +17 -0
- data/lib/arspy/operators/selector.rb +28 -0
- data/lib/arspy/operators.rb +40 -111
- data/lib/meta_programming/object.rb +2 -2
- data/spec/active_record.log +4327 -0
- data/spec/database.rb +85 -32
- data/spec/list_association_spec.rb +62 -0
- data/spec/list_field_spec.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/with_command_spec.rb +106 -0
- metadata +39 -7
data/spec/database.rb
CHANGED
@@ -1,80 +1,133 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
+
gem 'sqlite3-ruby', '>= 1.2.5'
|
3
4
|
gem 'activerecord', ENV['AR_VERSION'] ? "=#{ENV['AR_VERSION']}" : '>=2.3.2'
|
5
|
+
require 'sqlite3'
|
4
6
|
require 'active_record'
|
7
|
+
require 'factory_girl'
|
5
8
|
|
6
9
|
ActiveRecord::Base.establish_connection({'adapter' => 'sqlite3', 'database' => ':memory:'})
|
7
10
|
ActiveRecord::Base.logger = Logger.new("#{File.dirname(__FILE__)}/active_record.log")
|
8
11
|
cx = ActiveRecord::Base.connection
|
9
12
|
|
10
|
-
cx.create_table(:
|
13
|
+
cx.create_table(:users, :force=>true) do |t|
|
11
14
|
t.string :first_name
|
12
15
|
t.string :last_name
|
13
16
|
t.integer :age
|
14
17
|
t.boolean :active
|
15
18
|
end
|
16
|
-
|
17
|
-
class Person < ActiveRecord::Base
|
19
|
+
class User < ActiveRecord::Base
|
18
20
|
has_many :friendships
|
19
21
|
has_many :friends, :through=>:friendships
|
20
22
|
has_many :blogs
|
21
23
|
has_many :comments
|
22
24
|
|
23
|
-
def
|
25
|
+
def name; "#{first_name} #{last_name}"; end
|
24
26
|
end
|
25
27
|
|
26
28
|
cx.create_table(:friendships, :force=>true) do |t|
|
27
|
-
t.references :
|
29
|
+
t.references :user
|
28
30
|
t.references :friend
|
29
31
|
t.integer :years_known
|
30
32
|
end
|
31
|
-
|
32
33
|
class Friendship < ActiveRecord::Base
|
33
|
-
belongs_to :
|
34
|
-
belongs_to :friend, :
|
34
|
+
belongs_to :user
|
35
|
+
belongs_to :friend, :class_name=>'User'
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
fnames = ['John', 'Ted', 'Jan', 'Beth', 'Mark', 'Mary']
|
39
|
+
lnames = ['Patrick', 'Hanson', 'Partrich', 'Meyers', 'Dougherty', 'Smith']
|
40
|
+
Factory.define(:user) do |f|
|
41
|
+
f.sequence(:first_name) {|n| fnames[n-1]}
|
42
|
+
f.sequence(:last_name) {|n| lnames[n-1]}
|
43
|
+
f.sequence(:age){|n| 20 + (n-1) }
|
44
|
+
f.sequence(:active){|n| (n-1).odd? }
|
42
45
|
end
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
belongs_to :person
|
58
|
-
belongs_to :blog
|
47
|
+
users=Hash[*fnames.map{|fn| [fn.downcase.to_sym, Factory(:user)]}.flatten]
|
48
|
+
|
49
|
+
friends = {
|
50
|
+
:john => [:beth, :mark],
|
51
|
+
:ted => [:jan, :beth, :john],
|
52
|
+
:jan => [:ted, :john, :jan, :beth, :mark],
|
53
|
+
:beth => [:john],
|
54
|
+
:mark => [:john, :jan]
|
55
|
+
}
|
56
|
+
friends.each do |user, friends_list|
|
57
|
+
friends_list.each do |friend|
|
58
|
+
users[user].friends << users[friend]
|
59
|
+
end
|
59
60
|
end
|
60
61
|
|
61
62
|
cx.create_table(:images, :force=>true) do |t|
|
62
63
|
t.string :caption
|
63
64
|
t.integer :size
|
64
65
|
end
|
65
|
-
|
66
66
|
class Image < ActiveRecord::Base
|
67
|
-
|
67
|
+
has_many :blog, :as=>:asset
|
68
68
|
end
|
69
69
|
|
70
70
|
cx.create_table(:recordings, :force=>true) do |t|
|
71
71
|
t.string :title
|
72
72
|
t.integer :duration
|
73
73
|
end
|
74
|
-
|
75
74
|
class Recording < ActiveRecord::Base
|
76
|
-
|
75
|
+
has_many :blog, :as=>:asset
|
76
|
+
end
|
77
|
+
|
78
|
+
images = ['dogs', 'cats', 'rabbits'].inject([]) do |array, name|
|
79
|
+
array << Image.create(:caption=>name, :size=>((array.size+1)*1024))
|
80
|
+
end
|
81
|
+
recordings = ['kittens', 'puppies', 'parrots'].inject([]) do |array, name|
|
82
|
+
array << Recording.create(:title=>name, :duration=>(10*(array.size+1)))
|
77
83
|
end
|
78
84
|
|
85
|
+
cx.create_table(:blogs, :force=>true) do |t|
|
86
|
+
t.references :user
|
87
|
+
t.string :title
|
88
|
+
t.datetime :published_at
|
89
|
+
t.references :asset, :polymorphic=>true, :null=>true
|
90
|
+
end
|
91
|
+
class Blog < ActiveRecord::Base
|
92
|
+
belongs_to :user
|
93
|
+
belongs_to :asset, :polymorphic=>true
|
94
|
+
has_many :comments
|
95
|
+
end
|
96
|
+
dates = [2.months.ago, 4.months.ago, 6.months.ago, 8.months.ago]
|
97
|
+
Factory.define(:blog) do |f|
|
98
|
+
f.sequence(:title){|n| "blog_title_#{n}"}
|
99
|
+
f.sequence(:asset_id){|n| (n-1).odd? ? images[((n-1)/2)%images.size] : recordings[((n-1)/2)%recordings.size]}
|
100
|
+
f.sequence(:asset_type){|n| (n-1).odd? ? 'Image' : 'Recording'}
|
101
|
+
f.sequence(:published_at){|n| dates[(n-1)%dates.size]}
|
102
|
+
end
|
79
103
|
|
104
|
+
cx.create_table(:comments, :force=>true) do |t|
|
105
|
+
t.references :user
|
106
|
+
t.references :blog
|
107
|
+
t.string :comment
|
108
|
+
end
|
109
|
+
class Comment < ActiveRecord::Base
|
110
|
+
belongs_to :user
|
111
|
+
belongs_to :blog
|
112
|
+
end
|
113
|
+
|
114
|
+
comments = ['I agree', 'I disagree', 'I like it.', 'I do not like it at all.']
|
115
|
+
user_array = users.values.sort{|a,b| a.last_name <=> b.last_name}
|
116
|
+
user_array.each_with_index do |user, index|
|
117
|
+
0..(index%(users.size/2)).times do
|
118
|
+
blog = Factory.build(:blog)
|
119
|
+
blog.user = user
|
120
|
+
blog.save!
|
121
|
+
|
122
|
+
start_index = user_array.index(user)
|
123
|
+
commenters = user_array.reject{|u| u == user}
|
124
|
+
start_index = start_index >= commenters.size ? 0 : start_index
|
125
|
+
0..(index%(users.size)).times do |t|
|
126
|
+
comment = Comment.new(:comment=>comments[index%comments.size])
|
127
|
+
comment.user = commenters[(start_index + t)%commenters.size]
|
128
|
+
comment.blog = blog
|
129
|
+
comment.save!
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
80
133
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "The 'la' command" do
|
4
|
+
user_association_names = %w(friendships friends blogs comments)
|
5
|
+
describe "for an ActiveRecord class" do
|
6
|
+
it "should not raise an exception" do
|
7
|
+
lambda { User.la :data }.should_not raise_exception
|
8
|
+
end
|
9
|
+
it "should return list of association" do
|
10
|
+
User.la(:data).map{|d| d.first }.should =~ user_association_names
|
11
|
+
end
|
12
|
+
end
|
13
|
+
describe "for an ActiveRecord object" do
|
14
|
+
it "should not raise an exception" do
|
15
|
+
lambda { User.find(1).la :data }.should_not raise_exception
|
16
|
+
end
|
17
|
+
it "should return association names" do
|
18
|
+
User.find(1).la(:data).map{|d| d.first}.should =~ user_association_names
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe "for an array of ActiveRecord objects" do
|
22
|
+
it "should not raise an exception" do
|
23
|
+
lambda {
|
24
|
+
User.all.map{|u| u}.la(:data)
|
25
|
+
}.should_not raise_exception
|
26
|
+
end
|
27
|
+
it "should return all associations" do
|
28
|
+
User.all.map{|u| u}.la(:data).map{|d| d.first}.should =~ user_association_names
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe "for association collection" do
|
32
|
+
it "should not raise an exception" do
|
33
|
+
lambda { User.all.la :data }.should_not raise_exception
|
34
|
+
end
|
35
|
+
it "should return all associations" do
|
36
|
+
User.all.la(:data).map{|d| d.first}.should =~ user_association_names
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "The list_association operation" do
|
42
|
+
user_association_class_names = %w((Friendship) (User) (Blog) (Comment))
|
43
|
+
blog_association_class_names = %w((User) (*) (Comment))
|
44
|
+
comment_association_class_names = %w((User) (Blog))
|
45
|
+
friendship_association_class_names = %w((User) (User))
|
46
|
+
user_association_types = %w(has_many has_many has_many has_many)
|
47
|
+
blog_association_types = %w(belongs_to belongs_to has_many)
|
48
|
+
comment_association_types = %w(belongs_to belongs_to)
|
49
|
+
friendship_association_types = %w(belongs_to belongs_to)
|
50
|
+
it "should return the correct class names for associations" do
|
51
|
+
User.la(:data).map{|d| d[2] }.should =~ user_association_class_names
|
52
|
+
Blog.la(:data).map{|d| d[2] }.should =~ blog_association_class_names
|
53
|
+
Comment.la(:data).map{|d| d[2]}.should =~ comment_association_class_names
|
54
|
+
Friendship.la(:data).map{|d| d[2]}.should =~ friendship_association_class_names
|
55
|
+
end
|
56
|
+
it "should return the correct assocation types" do
|
57
|
+
User.la(:data).map{|d| d[1] }.should =~ user_association_types
|
58
|
+
Blog.la(:data).map{|d| d[1] }.should =~ blog_association_types
|
59
|
+
Comment.la(:data).map{|d| d[1]}.should =~ comment_association_types
|
60
|
+
Friendship.la(:data).map{|d| d[1]}.should =~ friendship_association_types
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "The 'wi' command" do
|
4
|
+
describe "on an ActiveRecord class" do
|
5
|
+
it "should raise a NoMethodError" do
|
6
|
+
lambda { User.wi() }.should raise_exception(NoMethodError)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
describe "on an ActiveRecord object" do
|
10
|
+
it "should raise a NoMethodError" do
|
11
|
+
lambda { User.find(1).wi() }.should raise_exception(NoMethodError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe "on an array of ActiveRecord object" do
|
15
|
+
before(:each) do
|
16
|
+
@users = User.all.map{|u| u}
|
17
|
+
end
|
18
|
+
it "should not raise an exception" do
|
19
|
+
lambda { @users.wi }.should_not raise_exception
|
20
|
+
end
|
21
|
+
end
|
22
|
+
describe "on an Association collection" do
|
23
|
+
before(:each) do
|
24
|
+
@users = User.all
|
25
|
+
end
|
26
|
+
it "should not raise an exception" do
|
27
|
+
lambda { @users.wi }.should_not raise_exception
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
describe "The 'wi' command" do
|
35
|
+
describe "containing a string with an expression for evaluation" do
|
36
|
+
describe "to test an attrbiute of the preceding object type" do
|
37
|
+
it "should return only the preceding objects passing test" do
|
38
|
+
Boss.create(6, :blogs) do |blogs|
|
39
|
+
users = blogs.where(1,2).have(2, :users)
|
40
|
+
|
41
|
+
end
|
42
|
+
special_users =
|
43
|
+
Boss.create(:users).with_usernames('jon', 'joe', 'pete'
|
44
|
+
).
|
45
|
+
:username=>['jon', 'joe', 'pete']
|
46
|
+
).with_every(:password=>'password').with_only
|
47
|
+
do
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
Boss.create(3, :users, :username=>['jon', 'joe', 'pete']) do
|
53
|
+
where(:users, 1..2).are_friends_with(:user, 3)
|
54
|
+
where(:user, 3).is_friends_with(:users, 1..2)
|
55
|
+
Boss.create(6, :blogs) do
|
56
|
+
where(:blogs, 1..2).belong_to(:user, 1)
|
57
|
+
where(:blog, 3).belongs_to(:user, 2)
|
58
|
+
where(:user, 2).has(:blog, 3)
|
59
|
+
where(:user, 3).has(:blogs, 4..6)
|
60
|
+
Boss.create(6, :comments) do
|
61
|
+
where(:comments).belong_to(:users, 1..3)
|
62
|
+
where(:comments).belongs_to(:blog, :where=>'blog.user != comment.user')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Blog.create(6) do |blogs|
|
68
|
+
blogs.with(1,2).having(2, :users)
|
69
|
+
end
|
70
|
+
|
71
|
+
Blog.all.wi("user.first_name == 'John'").each do |blog|
|
72
|
+
blog.user.first_name.should == 'John'
|
73
|
+
end
|
74
|
+
Blog.all.wi("user.last_name =~ /^Pa/").user.name.should =~ [/Patrick/, /Partrich/]
|
75
|
+
Blog.all.user.wi("last_name =~ /^Pa/").user.last_name.should include(/Patrick/, /Partrich/)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
describe "testing a method of the preceding object type" do
|
79
|
+
it "should return only the objects passing the test" do
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
describe "containing a set of strings" do
|
85
|
+
|
86
|
+
end
|
87
|
+
describe "containing an integer" do
|
88
|
+
|
89
|
+
end
|
90
|
+
describe "containing a set of integers" do
|
91
|
+
|
92
|
+
end
|
93
|
+
describe "containing a range" do
|
94
|
+
|
95
|
+
end
|
96
|
+
describe "contianing a set of ranges" do
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "The 'with' command containing a hash" do
|
103
|
+
describe ""
|
104
|
+
end
|
105
|
+
|
106
|
+
|
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
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeff Patmon
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-24 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,8 +27,8 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
- 1
|
30
|
-
-
|
31
|
-
version: 0.1.
|
30
|
+
- 4
|
31
|
+
version: 0.1.4
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
description: Active Record Spy
|
@@ -41,6 +41,31 @@ extra_rdoc_files: []
|
|
41
41
|
|
42
42
|
files:
|
43
43
|
- lib/meta_programming/object.rb
|
44
|
+
- lib/arspy/operators/attribute_test/range_test.rb
|
45
|
+
- lib/arspy/operators/attribute_test/integer_test.rb
|
46
|
+
- lib/arspy/operators/attribute_test/string_test.rb
|
47
|
+
- lib/arspy/operators/attribute_test/base.rb
|
48
|
+
- lib/arspy/operators/attribute_test/regexp_test.rb
|
49
|
+
- lib/arspy/operators/attribute_test/float_test.rb
|
50
|
+
- lib/arspy/operators/attribute_test/unsupported_test.rb
|
51
|
+
- lib/arspy/operators/attribute_test.rb
|
52
|
+
- lib/arspy/operators/selector/hash_selector.rb
|
53
|
+
- lib/arspy/operators/selector/unsupported_selector.rb
|
54
|
+
- lib/arspy/operators/selector/base.rb
|
55
|
+
- lib/arspy/operators/selector/string_selector.rb
|
56
|
+
- lib/arspy/operators/selector/attribute_selector.rb
|
57
|
+
- lib/arspy/operators/selector/integer_selector.rb
|
58
|
+
- lib/arspy/operators/selector/range_selector.rb
|
59
|
+
- lib/arspy/operators/interpreter/method_interpreter.rb
|
60
|
+
- lib/arspy/operators/interpreter/null_interpreter.rb
|
61
|
+
- lib/arspy/operators/interpreter/base.rb
|
62
|
+
- lib/arspy/operators/interpreter/attribute_interpreter.rb
|
63
|
+
- lib/arspy/operators/interpreter/association_interpreter.rb
|
64
|
+
- lib/arspy/operators/interpreter/abbreviated_association_interpreter.rb
|
65
|
+
- lib/arspy/operators/interpreter/abbreviated_attribute_interpreter.rb
|
66
|
+
- lib/arspy/operators/interpreter.rb
|
67
|
+
- lib/arspy/operators/abbreviations.rb
|
68
|
+
- lib/arspy/operators/selector.rb
|
44
69
|
- lib/arspy/class_extensions.rb
|
45
70
|
- lib/arspy/delegators/factory.rb
|
46
71
|
- lib/arspy/delegators/association_collection_extensions.rb
|
@@ -51,6 +76,11 @@ files:
|
|
51
76
|
- lib/arspy/operators.rb
|
52
77
|
- lib/meta_programming.rb
|
53
78
|
- lib/arspy.rb
|
79
|
+
- spec/list_field_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/with_command_spec.rb
|
82
|
+
- spec/active_record.log
|
83
|
+
- spec/list_association_spec.rb
|
54
84
|
- spec/database.rb
|
55
85
|
- init.rb
|
56
86
|
- LICENSE
|
@@ -89,5 +119,7 @@ rubygems_version: 1.3.6
|
|
89
119
|
signing_key:
|
90
120
|
specification_version: 3
|
91
121
|
summary: Rails console command line tool for browsing and inspecting the structure, associations and data of an ActiveRecord data model.
|
92
|
-
test_files:
|
93
|
-
|
122
|
+
test_files:
|
123
|
+
- spec/list_field_spec.rb
|
124
|
+
- spec/with_command_spec.rb
|
125
|
+
- spec/list_association_spec.rb
|