tractor 0.4.7 → 0.4.8
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/VERSION +1 -1
- data/lib/tractor/model/base.rb +5 -1
- data/performance/test.rb +44 -0
- data/spec/model/base_spec.rb +4 -0
- data/tractor.gemspec +3 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.8
|
data/lib/tractor/model/base.rb
CHANGED
@@ -39,6 +39,10 @@ module Tractor
|
|
39
39
|
Tractor.redis.smembers(key) || []
|
40
40
|
end
|
41
41
|
|
42
|
+
def count
|
43
|
+
ids.size
|
44
|
+
end
|
45
|
+
|
42
46
|
def all
|
43
47
|
ids.inject([]){|o, id| o << klass.find_by_id(id); o }
|
44
48
|
end
|
@@ -158,7 +162,7 @@ module Tractor
|
|
158
162
|
|
159
163
|
def find_by_id(id)
|
160
164
|
obj_data = Tractor.redis.mapped_hmget("#{self}:#{id}", *attributes.keys)
|
161
|
-
return nil if obj_data.
|
165
|
+
return nil if obj_data.values.compact.empty?
|
162
166
|
new(obj_data)
|
163
167
|
end
|
164
168
|
|
data/performance/test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'tractor'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
Tractor.connectdb
|
8
|
+
Tractor.flushdb
|
9
|
+
|
10
|
+
class Person < Tractor::Model::Base
|
11
|
+
attribute :id
|
12
|
+
attribute :first_name, :index => true
|
13
|
+
attribute :last_name, :index => true
|
14
|
+
attribute :awesome, :type => :boolean, :index => true
|
15
|
+
attribute :company_id, :index => true
|
16
|
+
end
|
17
|
+
|
18
|
+
class Company < Tractor::Model::Base
|
19
|
+
association :people, Person
|
20
|
+
|
21
|
+
attribute :id
|
22
|
+
attribute :name
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
100.times do |i|
|
27
|
+
Company.create(:id => i+1, :name => Faker::Company.name)
|
28
|
+
end
|
29
|
+
|
30
|
+
10000.times do |i|
|
31
|
+
Person.create(
|
32
|
+
:id => i+1,
|
33
|
+
:first_name => Faker::Name.first_name,
|
34
|
+
:last_name => Faker::Name.last_name,
|
35
|
+
:awesome => rand(2)==0,
|
36
|
+
:company_id => rand(Company.count)+1)
|
37
|
+
end
|
38
|
+
|
39
|
+
Company.all.each do |company|
|
40
|
+
t1 = Time.now
|
41
|
+
employees = company.people.all
|
42
|
+
t2 = Time.now
|
43
|
+
puts "Company #{company.id} has #{employees.size} employees and it took #{t2-t1} seconds to retrieve them all"
|
44
|
+
end
|
data/spec/model/base_spec.rb
CHANGED
@@ -103,6 +103,10 @@ describe Tractor::Model::Base do
|
|
103
103
|
game.players.ids.should == [player1.id]
|
104
104
|
end
|
105
105
|
|
106
|
+
it "adds a count method for the set that returns the size of the association" do
|
107
|
+
game.players.count.should == 1
|
108
|
+
end
|
109
|
+
|
106
110
|
it "automatically adds items to association when they are created" do
|
107
111
|
bocci_ball = Tractor::Model::Game.create({ :id => "bocci_ball" })
|
108
112
|
Tractor::Model::Player.create({ :id => "tobias", :name => "deciduous", :game_id => "bocci_ball" })
|
data/tractor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tractor}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shane Wolf"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-01}
|
13
13
|
s.description = %q{Very simple object mappings for ruby objects}
|
14
14
|
s.email = %q{shanewolf@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/tractor.rb",
|
27
27
|
"lib/tractor/model/base.rb",
|
28
28
|
"lib/tractor/model/mapper.rb",
|
29
|
+
"performance/test.rb",
|
29
30
|
"spec/model/base_spec.rb",
|
30
31
|
"spec/model/mapper_spec.rb",
|
31
32
|
"spec/spec.opts",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 8
|
10
|
+
version: 0.4.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shane Wolf
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-01 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/tractor.rb
|
54
54
|
- lib/tractor/model/base.rb
|
55
55
|
- lib/tractor/model/mapper.rb
|
56
|
+
- performance/test.rb
|
56
57
|
- spec/model/base_spec.rb
|
57
58
|
- spec/model/mapper_spec.rb
|
58
59
|
- spec/spec.opts
|