mongoose 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Mongoose 0.1.1
1
+ = Mongoose 0.2.0
2
2
 
3
3
  A database management system written in Ruby. It has an ActiveRecord-like
4
4
  interface, uses Skiplists for its indexing, and Marshal for its data
@@ -11,7 +11,9 @@ serialization. I named it Mongoose, because, like Rudyard Kipling's
11
11
  Thanks to Logan Capaldo for letting me steal a lot of the code from KirbyRecord.
12
12
 
13
13
  Thanks to Ezra Zygmuntowicz and Fabien Franzen, whose ez_where Rails plugin,
14
- provided much of the inspiration for the query language.
14
+ provided much of the inspiration for the query language. Also, Ezra has
15
+ graciously taken the time to give me pointers on how to make Mongoose's query
16
+ language and api better.
15
17
 
16
18
  Thanks to everyone who gave me feedback on KirbyBase. I have tried to put all
17
19
  the lessons learned from developing that library to good use here.
@@ -56,7 +58,7 @@ db = Mongoose::Database.new
56
58
 
57
59
  # Create new table. Notice how you specify whether a column is indexed or not.
58
60
  db.create_table(:plane) do |tbl|
59
- tbl.add_indexed_column(:plane_name, :string)
61
+ tbl.add_indexed_column(:name, :string)
60
62
  tbl.add_column(:country, :string)
61
63
  tbl.add_indexed_column(:speed, :integer)
62
64
  tbl.add_column(:range, :integer)
@@ -64,7 +66,7 @@ end
64
66
 
65
67
  # Add a record.
66
68
  rec = Plane.new
67
- rec.plane_name = 'P-51'
69
+ rec.name = 'P-51'
68
70
  rec.country = 'USA'
69
71
  rec.speed = 402
70
72
  rec.range = 1205
@@ -73,24 +75,25 @@ rec.save
73
75
  # Various ways to find a record; should be familiar to ActiveRecord users.
74
76
  Plane.find(1) # Find record with id equal 1.
75
77
 
76
- Plane.find { |plane| plane.speed > 350 } # Find all planes with speed > 350.
78
+ Plane.find { speed > 350 } # Find all planes with speed > 350.
77
79
 
78
80
  Plane.find # Find all records.
79
81
 
80
- Plane.find(:first) { |plane| plane.country == 'USA' }
82
+ Plane.find(:first) { country == 'USA' } # Find first plane from USA.
81
83
 
82
- Plane.find do |plane| # Find all planes from either USA or
83
- plane.any do # Great Britain with speed > 400.
84
- plane.country == 'USA'
85
- plane.country == 'Great Britain'
84
+ Plane.find do # Find all planes from either USA or
85
+ any do # Great Britain with speed > 400.
86
+ country == 'USA'
87
+ country == 'Great Britain'
86
88
  end
87
- plane.speed > 400
89
+ speed > 400
88
90
  end
89
91
 
90
92
  # Delete a record.
91
93
  Plane.find(1).destroy
92
94
 
93
- # Close database.
95
+ # Close database. This will write the indexes out to disk so they can be
96
+ # initialized quickly next time.
94
97
  db.close
95
98
 
96
99
  == Manifest
@@ -11,3 +11,15 @@
11
11
  memory usage.
12
12
  * Cleaned up the code in SkipList class.
13
13
  * Added more unit tests.
14
+
15
+ 2006-07-21:: Version 0.2.0
16
+ * Added Table.create method. Thanks to Ezra Zygmuntowicz for this patch.
17
+ * Changed unit tests and examples to use Table.create rather than Table.new.
18
+ * Thanks to Ezra Zygmuntowicz, you no longer have to specify block parameters
19
+ in your queries, nor prefix all of the column names in queries with those
20
+ block parameters. This makes the query language so much cleaner. Thanks
21
+ again, Ezra!
22
+ * Logan Capaldo provided a patch for the Table.init_column method that
23
+ eliminated the string eval. Thanks Logan!
24
+ * Included a new example from Daniel Sheppard that shows how to integrate
25
+ ActiveRecord validations into Mongoose.
@@ -0,0 +1,56 @@
1
+ # This example comes from Daniel Sheppard. Thanks very much Daniel!
2
+ # It is an early example of how you can integrate ActiveRecord validations
3
+ # into Mongoose. Expect more on this in the future.
4
+
5
+ require 'rubygems'
6
+ require 'mongoose'
7
+ require 'active_support'
8
+ require 'active_record/base'
9
+ require 'active_record/validations'
10
+
11
+
12
+ class Mongoose::ActiveTable < Mongoose::Table
13
+ RecordNotSaved = ActiveRecord::RecordNotSaved
14
+ def update_attribute(name, value)
15
+ send(name.to_s + '=', value)
16
+ save
17
+ end
18
+ def new_record?
19
+ @id.nil?
20
+ end
21
+ def self.human_attribute_name(attribute_key_name) #:nodoc:
22
+ attribute_key_name.humanize
23
+ end
24
+ def save!
25
+ save || raise(RecordNotSaved)
26
+ end
27
+
28
+ def self.init_column(col_name, col_def, col_class)
29
+ super
30
+ meth = <<-END_OF_STRING
31
+ def #{col_name}_before_type_cast
32
+ #{col_name}
33
+ end
34
+ END_OF_STRING
35
+ self.class_eval(meth)
36
+ end
37
+
38
+ include ActiveRecord::Validations
39
+ end
40
+
41
+
42
+ class Monkey < Mongoose::ActiveTable
43
+ validates_numericality_of :arms
44
+ end
45
+
46
+
47
+ Mongoose::Table.db = Mongoose::Database.new
48
+ unless Mongoose::Table.db.table_exists?('monkey')
49
+ Mongoose::Table.db.create_table('monkey') do |t|
50
+ t.add_column 'arms', :integer
51
+ end
52
+ end
53
+
54
+ m = Monkey.new()
55
+ m.arms = '2a'
56
+ m.save!
@@ -28,11 +28,11 @@ db = Mongoose::Database.new
28
28
 
29
29
  # Create tables.
30
30
  db.create_table(:pilot) do |tbl|
31
- tbl.add_indexed_column(:pilot_name, :string)
31
+ tbl.add_indexed_column(:name, :string)
32
32
  tbl.add_column(:years_flying, :integer)
33
33
  end
34
34
  db.create_table(:plane) do |tbl|
35
- tbl.add_indexed_column(:plane_name, :string)
35
+ tbl.add_indexed_column(:name, :string)
36
36
  tbl.add_column(:country, :string)
37
37
  tbl.add_indexed_column(:speed, :integer)
38
38
  tbl.add_column(:range, :integer)
@@ -45,57 +45,23 @@ db.create_table(:flight) do |tbl|
45
45
  end
46
46
 
47
47
  # Create Pilot records.
48
- doolittle = Pilot.new
49
- doolittle.pilot_name = 'Doolitle, James'
50
- doolittle.years_flying = 15
51
- doolittle.save
52
-
53
- amelia = Pilot.new
54
- amelia.pilot_name = 'Earhart, Amelia'
55
- amelia.years_flying = 10
56
- amelia.save
48
+ doolittle = Pilot.create :name => 'Doolitle, James', :years_flying => 15
49
+ amelia = Pilot.create :name => 'Earhart, Amelia', :years_flying => 10
57
50
 
58
51
  # Create Plane records.
59
- rec = Plane.new
60
- rec.plane_name = 'P-51'
61
- rec.country = 'USA'
62
- rec.speed = 402
63
- rec.range = 1205
64
- rec.pilot_id = doolittle.id
65
- rec.save
66
-
67
- rec = Plane.new
68
- rec.plane_name = 'Spitfire'
69
- rec.country = 'Great Britain'
70
- rec.speed = 333
71
- rec.range = 454
72
- rec.pilot_id = amelia.id
73
- rec.save
52
+ Plane.create :name => 'P-51', :country => 'USA', :speed => 402,
53
+ :range => 1205, :pilot_id => doolittle.id
54
+ Plane.create :name => 'Spitfire', :country => 'Great Britain', :speed => 333,
55
+ :range => 454, :pilot_id => amelia.id
74
56
 
75
57
  # Create Flight records.
76
- rec = Flight.new
77
- rec.pilot_id = doolittle.id
78
- rec.origin = 'Army'
79
- rec.destination = 'Nowhere'
80
- rec.save
81
-
82
- rec = Flight.new
83
- rec.pilot_id = amelia.id
84
- rec.origin = 'USA'
85
- rec.destination = 'France'
86
-
87
- rec.save
88
- rec = Flight.new
89
- rec.pilot_id = amelia.id
90
- rec.origin = 'USA'
91
- rec.destination = 'Phillipines'
92
- rec.save
93
-
94
- rec = Flight.new
95
- rec.pilot_id = amelia.id
96
- rec.origin = 'China'
97
- rec.destination = 'Unknown'
98
- rec.save
58
+ Flight.create :pilot_id => doolittle.id, :origin => 'Army',
59
+ :destination => 'Nowhere'
60
+ Flight.create :pilot_id => amelia.id, :origin => 'USA', :destination => 'France'
61
+ Flight.create :pilot_id => amelia.id, :origin => 'USA',
62
+ :destination => 'Phillipines'
63
+ Flight.create :pilot_id => amelia.id, :origin => 'China',
64
+ :destination => 'Unknown'
99
65
 
100
66
  puts "\n\nFind Jimmy Doolittle"
101
67
  rec = Pilot.find(1)
@@ -22,48 +22,27 @@ db = Mongoose::Database.new
22
22
  # Create new table. Notice how you specify whether a column is indexed or not.
23
23
  unless ARGV[0] == 'keep-data'
24
24
  db.create_table(:plane) do |tbl|
25
- tbl.add_indexed_column(:plane_name, :string)
25
+ tbl.add_indexed_column(:name, :string)
26
26
  tbl.add_column(:country, :string)
27
27
  tbl.add_indexed_column(:speed, :integer)
28
28
  tbl.add_column(:range, :integer)
29
29
  end
30
30
 
31
31
  # Add records.
32
- rec = Plane.new
33
- rec.plane_name = 'P-51'
34
- rec.country = 'USA'
35
- rec.speed = 402
36
- rec.range = 1205
37
- rec.save
38
-
39
- rec2 = Plane.new
40
- rec2.plane_name = 'Spitfire'
41
- rec2.country = 'Great Britain'
42
- rec2.speed = 333
43
- rec2.range = 454
44
- rec2.save
45
-
46
- rec3 = Plane.new
47
- rec3.plane_name = 'ME-109'
48
- rec3.country = 'Germany'
49
- rec3.speed = 354
50
- rec3.range = 501
51
- rec3.save
52
-
53
- rec4 = Plane.new
54
- rec4.plane_name = 'P-39'
55
- rec4.country = 'USA'
56
- rec4.range = 701
32
+ Plane.create :name => 'P-51', :country => 'USA', :speed => 402, :range => 1205
33
+ Plane.create :name => 'Spitfire', :country => 'Great Britain', :speed => 333,
34
+ :range => 454
35
+ Plane.create :name => 'ME-109', :country => 'Germany', :speed => 354,
36
+ :range => 501
57
37
 
58
38
  # Forgot value for speed, which is a required field.
59
39
  begin
60
- rec4.save
40
+ Plane.create :name => 'P-39', :country => 'USA', :range => 701
61
41
  rescue RuntimeError => e
62
42
  puts e
63
43
  end
64
44
 
65
- rec4.speed = 339
66
- rec4.save
45
+ Plane.create :name => 'P-39', :country => 'USA', :range => 701, :speed => 339
67
46
  end
68
47
 
69
48
  puts "\n\nFind P-51 record by ID"
@@ -77,40 +56,40 @@ if p_51
77
56
  end
78
57
 
79
58
  puts "\n\nFind all records with speed greater than 350 mph"
80
- result = Plane.find { |plane| plane.speed > 350 }
59
+ result = Plane.find { speed > 350 }
81
60
  p result
82
61
 
83
62
  puts "\n\nFind all US planes with speed greater than 300 mph"
84
- result = Plane.find { |plane| plane.country == 'USA' and plane.speed > 300 }
63
+ result = Plane.find { country == 'USA' and speed > 300 }
85
64
  p result
86
65
 
87
66
  puts "\n\nFind all British planes with speed greater than 300 mph"
88
- result = Plane.find do |plane|
89
- plane.country == 'Great Britain' and plane.speed > 300
67
+ result = Plane.find do
68
+ country == 'Great Britain' and speed > 300
90
69
  end
91
70
  p result
92
71
 
93
72
  puts "\n\nFind all Allied planes"
94
- result = Plane.find do |plane|
95
- plane.any do
96
- plane.country == 'USA'
97
- plane.country == 'Great Britain'
73
+ result = Plane.find do
74
+ any do
75
+ country == 'USA'
76
+ country == 'Great Britain'
98
77
  end
99
78
  end
100
79
  p result
101
80
 
102
81
  puts "\n\nFind all Allied planes with speed greater than 400 mph"
103
- result = Plane.find do |plane|
104
- plane.any do
105
- plane.country == 'USA'
106
- plane.country == 'Great Britain'
82
+ result = Plane.find do
83
+ any do
84
+ country == 'USA'
85
+ country == 'Great Britain'
107
86
  end
108
- plane.speed > 400
87
+ speed > 400
109
88
  end
110
89
  p result
111
90
 
112
91
  # Delete Spitfire record.
113
- spitfire = Plane.find(:first) { |plane| plane.plane_name == 'Spitfire' }
92
+ spitfire = Plane.find(:first) { name == 'Spitfire' }
114
93
 
115
94
  spitfire.destroy if spitfire
116
95
 
@@ -22,7 +22,7 @@ require 'mongoose/util'
22
22
  #
23
23
  module Mongoose
24
24
 
25
- VERSION = '0.1.1'
25
+ VERSION = '0.2.0'
26
26
  DATA_TYPES = [:string, :integer, :float, :time, :date, :datetime, :boolean]
27
27
  TBL_EXT = '.mgt'
28
28
  TBL_HDR_EXT = '.mgh'
@@ -46,7 +46,7 @@ class Database
46
46
  tbl_header[:deleted_recs_counter] = 0
47
47
  tbl_header[:columns] = []
48
48
  tbl_header[:columns] << { :name => :id, :data_type => :integer,
49
- :class => IDColumn.to_s }
49
+ :class => IDColumn.to_s }
50
50
 
51
51
  File.open(File.join(@path, table_name.to_s + TBL_HDR_EXT), 'w') do |f|
52
52
  YAML.dump(tbl_header, f)
@@ -72,8 +72,8 @@ class Table
72
72
 
73
73
  define_method(kind.to_sym) do
74
74
  klass = Object.const_get(class_name)
75
- Collection.new(self, klass.find { |r|
76
- r.send(col) == self.instance_eval { @id } })
75
+ parent_id = @id
76
+ Collection.new(self, klass.find { send(col) == parent_id })
77
77
  end
78
78
  end
79
79
 
@@ -87,7 +87,8 @@ class Table
87
87
 
88
88
  define_method(kind.to_sym) do
89
89
  klass = Object.const_get(class_name)
90
- klass.find(:first) { |r| r.send(col) == self.instance_eval { @id } }
90
+ parent_id = @id
91
+ klass.find(:first) { send(col) == parent_id }
91
92
  end
92
93
  end
93
94
 
@@ -160,12 +161,11 @@ class Table
160
161
 
161
162
  self.columns << col
162
163
 
163
- meth = <<-END_OF_STRING
164
- def self.#{col_name}
165
- self.columns.detect { |c| c.name == "#{col_name}".to_sym }
164
+ (class << self; self; end).class_eval do
165
+ define_method(col_name) do
166
+ self.columns.detect { |c| c.name == col_name.to_sym }
167
+ end
166
168
  end
167
- END_OF_STRING
168
- self.class_eval(meth)
169
169
 
170
170
  self.class_eval do
171
171
  attr_accessor col_name
@@ -219,10 +219,22 @@ class Table
219
219
  self.add_column(col_name, col_def, SkipListIndexColumn)
220
220
  end
221
221
 
222
+ #-----------------------------------------------------------------------------
223
+ # Table.create
224
+ #-----------------------------------------------------------------------------
225
+ def self.create(options={})
226
+ rec = new
227
+ options.each do |k,v|
228
+ rec.send("#{k}=", v) if self.column_names.include? k
229
+ end
230
+ rec.save
231
+ rec
232
+ end
233
+
222
234
  #-----------------------------------------------------------------------------
223
235
  # Table.find
224
236
  #-----------------------------------------------------------------------------
225
- def self.find(*args)
237
+ def self.find(*args, &block)
226
238
  # If searching for just one id or a group of ids...
227
239
  if args[0].is_a?(Integer)
228
240
  if args.size == 1
@@ -233,7 +245,7 @@ class Table
233
245
  else
234
246
  result = []
235
247
  # If passed a query block...
236
- if block_given?
248
+ if block
237
249
  self.query.clear
238
250
  query_start = true
239
251
  sub_q = false
@@ -241,7 +253,7 @@ class Table
241
253
  sub_q_result = []
242
254
 
243
255
  # Grab the query block
244
- yield self
256
+ instance_eval(&block)
245
257
 
246
258
  # Step through the query block...
247
259
  self.query.each_with_index do |q,i|
@@ -26,12 +26,12 @@ class TestRelations < Test::Unit::TestCase
26
26
  @db = Mongoose::Database.new(:path => Dir.tmpdir)
27
27
 
28
28
  @db.create_table(:pilot) do |tbl|
29
- tbl.add_indexed_column(:pilot_name, :string)
29
+ tbl.add_indexed_column(:name, :string)
30
30
  tbl.add_column(:years_flying, :integer)
31
31
  end
32
32
 
33
33
  @db.create_table(:plane) do |tbl|
34
- tbl.add_indexed_column(:plane_name, :string)
34
+ tbl.add_indexed_column(:name, :string)
35
35
  tbl.add_column(:country, :string)
36
36
  tbl.add_indexed_column(:speed, :integer)
37
37
  tbl.add_column(:range, :integer)
@@ -44,55 +44,22 @@ class TestRelations < Test::Unit::TestCase
44
44
  tbl.add_column(:pilot_id, :integer)
45
45
  end
46
46
 
47
- @doolittle = Pilot.new
48
- @doolittle.pilot_name = 'Doolittle, James'
49
- @doolittle.years_flying = 15
50
- @doolittle.save
51
-
52
- @amelia = Pilot.new
53
- @amelia.pilot_name = 'Earhart, Amelia'
54
- @amelia.years_flying = 10
55
- @amelia.save
56
-
57
- rec = Plane.new
58
- rec.plane_name = 'P-51'
59
- rec.country = 'USA'
60
- rec.speed = 402
61
- rec.range = 1205
62
- rec.pilot_id = @doolittle.id
63
- rec.save
64
-
65
- rec = Plane.new
66
- rec.plane_name = 'Spitfire'
67
- rec.country = 'Great Britain'
68
- rec.speed = 333
69
- rec.range = 454
70
- rec.pilot_id = @amelia.id
71
- rec.save
72
-
73
- rec = Flight.new
74
- rec.pilot_id = @doolittle.id
75
- rec.origin = 'Army'
76
- rec.destination = 'Nowhere'
77
- rec.save
78
-
79
- rec = Flight.new
80
- rec.pilot_id = @amelia.id
81
- rec.origin = 'USA'
82
- rec.destination = 'France'
83
-
84
- rec.save
85
- rec = Flight.new
86
- rec.pilot_id = @amelia.id
87
- rec.origin = 'USA'
88
- rec.destination = 'Phillipines'
89
- rec.save
90
-
91
- rec = Flight.new
92
- rec.pilot_id = @amelia.id
93
- rec.origin = 'China'
94
- rec.destination = 'Unknown'
95
- rec.save
47
+ @doolittle = Pilot.create :name => 'Doolittle, James', :years_flying => 15
48
+ @amelia = Pilot.create :name => 'Earhart, Amelia', :years_flying => 10
49
+
50
+ Plane.create :name => 'P-51', :country => 'USA', :speed => 402,
51
+ :range => 1205, :pilot_id => @doolittle.id
52
+ Plane.create :name => 'Spitfire', :country => 'Great Britain',
53
+ :speed => 333, :range => 454, :pilot_id => @amelia.id
54
+
55
+ Flight.create :pilot_id => @doolittle.id, :origin => 'Army',
56
+ :destination => 'Nowhere'
57
+ Flight.create :pilot_id => @amelia.id, :origin => 'USA',
58
+ :destination => 'France'
59
+ Flight.create :pilot_id => @amelia.id, :origin => 'USA',
60
+ :destination => 'Phillipines'
61
+ Flight.create :pilot_id => @amelia.id, :origin => 'China',
62
+ :destination => 'Unknown'
96
63
  end
97
64
 
98
65
  def teardown
@@ -103,7 +70,7 @@ class TestRelations < Test::Unit::TestCase
103
70
  end
104
71
 
105
72
  def test_has_one
106
- assert_equal('P-51', @doolittle.plane.plane_name)
73
+ assert_equal('P-51', @doolittle.plane.name)
107
74
  end
108
75
 
109
76
  def test_has_many_001
@@ -112,28 +79,24 @@ class TestRelations < Test::Unit::TestCase
112
79
  end
113
80
 
114
81
  def test_has_many_002
115
- rec = Flight.new
116
- rec.pilot_id = @amelia.id
117
- rec.origin = 'Tuscon'
118
- rec.destination = 'Phoenix'
82
+ rec = Flight.create :pilot_id => @amelia.id, :origin => 'Tuscon',
83
+ :destination => 'Phoenix'
119
84
  @amelia.flights << rec
120
85
 
121
86
  assert(@amelia.flights.any? {|f| f.origin == 'Tuscon'})
122
87
  end
123
88
 
124
89
  def test_belongs_to_001
125
- assert_equal('Earhart, Amelia', Plane.find(2).pilot.pilot_name)
126
- assert_equal('Doolittle, James', Flight.find(1).pilot.pilot_name)
90
+ assert_equal('Earhart, Amelia', Plane.find(2).pilot.name)
91
+ assert_equal('Doolittle, James', Flight.find(1).pilot.name)
127
92
  end
128
93
 
129
94
  def test_belongs_to_002
130
- red_baron = Pilot.new
131
- red_baron.pilot_name = 'Baron, The Red'
132
- red_baron.years_flying = 50
133
- spitfire = Plane.find(:first) {|plane| plane.plane_name == 'Spitfire'}
95
+ red_baron = Pilot.create :name => 'Baron, The Red', :years_flying => 50
96
+ spitfire = Plane.find(:first) { name == 'Spitfire'}
134
97
  spitfire.pilot = red_baron
135
98
 
136
- assert('Baron, The Red', spitfire.pilot.pilot_name)
137
- assert_equal('Spitfire', red_baron.plane.plane_name)
99
+ assert('Baron, The Red', spitfire.pilot.name)
100
+ assert_equal('Spitfire', red_baron.plane.name)
138
101
  end
139
102
  end
@@ -22,33 +22,14 @@ class TestTable < Test::Unit::TestCase
22
22
  tbl.add_column(:range, :integer)
23
23
  end
24
24
 
25
- rec = Plane.new
26
- rec.name = 'P-51'
27
- rec.country = 'USA'
28
- rec.speed = 402
29
- rec.range = 1205
30
- rec.save
31
-
32
- rec = Plane.new
33
- rec.name = 'Spitfire'
34
- rec.country = 'Great Britain'
35
- rec.speed = 333
36
- rec.range = 454
37
- rec.save
38
-
39
- rec = Plane.new
40
- rec.name = 'ME-109'
41
- rec.country = 'Germany'
42
- rec.speed = 351
43
- rec.range = 501
44
- rec.save
45
-
46
- rec = Plane.new
47
- rec.name = 'P-38'
48
- rec.country = 'USA'
49
- rec.speed = 401
50
- rec.range = 999
51
- rec.save
25
+ Plane.create :name => 'P-51', :country => 'USA', :speed => 402,
26
+ :range => 1205
27
+ Plane.create :name => 'Spitfire', :country => 'Great Britain',
28
+ :speed => 333, :range => 454
29
+ Plane.create :name => 'ME-109', :country => 'Germany', :speed => 351,
30
+ :range => 501
31
+ Plane.create :name => 'P-38', :country => 'USA', :speed => 401,
32
+ :range => 999
52
33
  end
53
34
 
54
35
  def teardown
@@ -64,14 +45,21 @@ class TestTable < Test::Unit::TestCase
64
45
  end
65
46
 
66
47
  def test_add_record
67
- rec = Plane.find(1)
48
+ rec = Plane.new
49
+ rec.name = 'Zero'
50
+ rec.country = 'Japan'
51
+ rec.speed = 377
52
+ rec.range = 888
53
+ rec.save
68
54
 
69
- assert(rec.is_a?(Plane))
70
- assert_equal(1, rec.id)
71
- assert_equal('P-51', rec.name)
72
- assert_equal('USA', rec.country)
73
- assert_equal(402, rec.speed)
74
- assert_equal(1205, rec.range)
55
+ rec2 = Plane.find(rec.id)
56
+
57
+ assert(rec2.is_a?(Plane))
58
+ assert_equal(rec.id, rec2.id)
59
+ assert_equal('Zero', rec2.name)
60
+ assert_equal('Japan', rec2.country)
61
+ assert_equal(377, rec2.speed)
62
+ assert_equal(888, rec2.range)
75
63
  end
76
64
 
77
65
  def test_update_record_001
@@ -95,7 +83,7 @@ class TestTable < Test::Unit::TestCase
95
83
  end
96
84
 
97
85
  def find_001
98
- rec = Plane.find(:first) { |plane| plane.name == 'P-51' }
86
+ rec = Plane.find(:first) { name == 'P-51' }
99
87
 
100
88
  assert(rec.is_a?(Plane))
101
89
  assert_equal(rec.name, 'P-51')
@@ -111,7 +99,7 @@ class TestTable < Test::Unit::TestCase
111
99
  end
112
100
 
113
101
  def find_002
114
- recs = Plane.find { |plane| plane.name == 'P-51' }
102
+ recs = Plane.find { name == 'P-51' }
115
103
 
116
104
  assert_equal(recs.size, 1)
117
105
  assert(recs.first.is_a?(Plane))
@@ -134,30 +122,30 @@ class TestTable < Test::Unit::TestCase
134
122
  end
135
123
 
136
124
  def find_003
137
- recs = Plane.find do |plane|
138
- plane.any do
139
- plane.country == 'USA'
140
- plane.country == 'Great Britain'
125
+ recs = Plane.find do
126
+ any do
127
+ country == 'USA'
128
+ country == 'Great Britain'
141
129
  end
142
130
  end
143
131
  assert_equal(recs.size, 3)
144
132
 
145
- recs = Plane.find do |plane|
146
- plane.any do
147
- plane.country == 'USA'
148
- plane.country == 'Great Britain'
133
+ recs = Plane.find do
134
+ any do
135
+ country == 'USA'
136
+ country == 'Great Britain'
149
137
  end
150
- plane.speed > 400
138
+ speed > 400
151
139
  end
152
140
  assert_equal(recs.size, 2)
153
141
 
154
- recs = Plane.find do |plane|
155
- plane.any do
156
- plane.country == 'USA'
157
- plane.country == 'Great Britain'
142
+ recs = Plane.find do
143
+ any do
144
+ country == 'USA'
145
+ country == 'Great Britain'
158
146
  end
159
- plane.speed > 400
160
- plane.range > 1000
147
+ speed > 400
148
+ range > 1000
161
149
  end
162
150
  assert_equal(recs.size, 1)
163
151
  assert_equal(recs.first.name, 'P-51')
@@ -173,23 +161,23 @@ class TestTable < Test::Unit::TestCase
173
161
  end
174
162
 
175
163
  def find_004
176
- recs = Plane.find { |plane| plane.name.one_of('P-51', 'ME-109') }
164
+ recs = Plane.find { name.one_of('P-51', 'ME-109') }
177
165
  assert_equal(recs.size, 2)
178
166
 
179
- recs = Plane.find { |plane| plane.country.one_of('USA', 'Germany') }
167
+ recs = Plane.find { country.one_of('USA', 'Germany') }
180
168
  assert_equal(recs.size, 3)
181
169
 
182
- recs = Plane.find { |plane| plane.speed.between(351, 400) }
170
+ recs = Plane.find { speed.between(351, 400) }
183
171
  assert_equal(0, recs.size)
184
172
 
185
- recs = Plane.find { |plane| plane.speed.between(351, 400, true) }
173
+ recs = Plane.find { speed.between(351, 400, true) }
186
174
  assert_equal(1, recs.size)
187
175
  assert_equal('ME-109', recs.first.name)
188
176
 
189
- recs = Plane.find { |plane| plane.range.between(450, 501) }
177
+ recs = Plane.find { range.between(450, 501) }
190
178
  assert_equal(1, recs.size)
191
179
 
192
- recs = Plane.find { |plane| plane.range.between(450, 501, false, true) }
180
+ recs = Plane.find { range.between(450, 501, false, true) }
193
181
  assert_equal(2, recs.size)
194
182
  end
195
183
 
@@ -203,7 +191,7 @@ class TestTable < Test::Unit::TestCase
203
191
  end
204
192
 
205
193
  def test_destroy
206
- rec = Plane.find(:first) { |plane| plane.name == 'P-51' }
194
+ rec = Plane.find(:first) { name == 'P-51' }
207
195
  rec.destroy
208
196
 
209
197
  recs = Plane.find
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: mongoose
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-07-20 00:00:00 -04:00
6
+ version: 0.2.0
7
+ date: 2006-07-21 00:00:00 -04:00
8
8
  summary: Mongoose is a pure_ruby database management system.
9
9
  require_paths:
10
10
  - lib
@@ -44,6 +44,7 @@ files:
44
44
  - test/tc_relations.rb
45
45
  - example/relation_examples.rb
46
46
  - example/simple_examples.rb
47
+ - example/activetable_example.rb
47
48
  test_files:
48
49
  - test/ts_mongoose.rb
49
50
  rdoc_options: []