passiverecord 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +9 -7
- data/lib/passive_record/associations.rb +16 -5
- data/passiverecord.gemspec +7 -4
- data/test/fixtures/candraspouses.yml +13 -0
- data/test/fixtures/fosses.rb +14 -0
- data/test/fixtures/rhizocables.yml +16 -0
- data/test/fixtures/sambocranks.yml +13 -0
- data/test/fixtures/schema.rb +31 -0
- data/test/test_associations.rb +20 -19
- data/test/test_helper.rb +2 -1
- metadata +11 -9
- data/test/fixtures/doors.yml +0 -9
- data/test/fixtures/furniture.rb +0 -41
- data/test/fixtures/furniture.yml +0 -13
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
CHANGELOG
|
2
|
-
Manifest
|
3
|
-
README
|
4
|
-
lib/passive_record.rb
|
5
2
|
lib/passive_record/associations.rb
|
6
3
|
lib/passive_record/base.rb
|
7
4
|
lib/passive_record/schema.rb
|
5
|
+
lib/passive_record.rb
|
6
|
+
Manifest
|
7
|
+
README
|
8
|
+
test/fixtures/candraspouses.yml
|
9
|
+
test/fixtures/continents.rb
|
10
|
+
test/fixtures/fosses.rb
|
11
|
+
test/fixtures/rhizocables.yml
|
12
|
+
test/fixtures/sambocranks.yml
|
13
|
+
test/fixtures/schema.rb
|
8
14
|
test/test_associations.rb
|
9
15
|
test/test_base.rb
|
10
16
|
test/test_helper.rb
|
11
|
-
test/fixtures/continents.rb
|
12
|
-
test/fixtures/doors.yml
|
13
|
-
test/fixtures/furniture.rb
|
14
|
-
test/fixtures/furniture.yml
|
@@ -104,6 +104,10 @@ module PassiveRecord
|
|
104
104
|
write_inheritable_hash :reflections, name => reflection
|
105
105
|
reflection
|
106
106
|
end
|
107
|
+
|
108
|
+
def reflections
|
109
|
+
read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {})
|
110
|
+
end
|
107
111
|
|
108
112
|
def add_multiple_associated_save_callbacks(association_name)
|
109
113
|
method_name = "validate_associated_records_for_#{association_name}".to_sym
|
@@ -176,16 +180,15 @@ module PassiveRecord
|
|
176
180
|
|
177
181
|
def collection_reader_method(reflection, association_proxy_class)
|
178
182
|
define_method(reflection.name) do |*params|
|
183
|
+
|
179
184
|
force_reload = params.first unless params.empty?
|
180
185
|
association = instance_variable_get("@#{reflection.name}")
|
181
|
-
|
182
186
|
unless association.respond_to?(:loaded?)
|
183
187
|
association = association_proxy_class.new(self, reflection)
|
184
188
|
instance_variable_set("@#{reflection.name}", association)
|
185
189
|
end
|
186
|
-
|
187
190
|
association.reload if force_reload
|
188
|
-
|
191
|
+
|
189
192
|
association
|
190
193
|
end
|
191
194
|
end
|
@@ -267,8 +270,16 @@ module PassiveRecord
|
|
267
270
|
ActiveRecord::Base.send(:compute_type, *args)
|
268
271
|
end
|
269
272
|
|
270
|
-
def reflect_on_association(
|
271
|
-
ActiveRecord::
|
273
|
+
def reflect_on_association(association)
|
274
|
+
reflections[association].is_a?(ActiveRecord::Reflection::AssociationReflection) ? reflections[association] : nil
|
275
|
+
end
|
276
|
+
|
277
|
+
def table_name
|
278
|
+
"table_name_foo"
|
279
|
+
end
|
280
|
+
|
281
|
+
def primary_key
|
282
|
+
"primary_key_bar"
|
272
283
|
end
|
273
284
|
|
274
285
|
end
|
data/passiverecord.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Passiverecord-0.
|
2
|
+
# Gem::Specification for Passiverecord-0.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{passiverecord}
|
7
|
-
s.version = "0.
|
8
|
-
s.date = %q{2007-
|
7
|
+
s.version = "0.2"
|
8
|
+
s.date = %q{2007-11-08}
|
9
9
|
s.summary = %q{Pacifying overactive records}
|
10
10
|
s.email = %q{jasper@ambethia.com}
|
11
11
|
s.homepage = %q{http://code.itred.org/projects/passive-record}
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Pacifying overactive records}
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.authors = ["Jason L Perry"]
|
16
|
-
s.files = ["CHANGELOG", "
|
16
|
+
s.files = ["CHANGELOG", "lib/passive_record/associations.rb", "lib/passive_record/base.rb", "lib/passive_record/schema.rb", "lib/passive_record.rb", "Manifest", "README", "test/fixtures/candraspouses.yml", "test/fixtures/continents.rb", "test/fixtures/fosses.rb", "test/fixtures/rhizocables.yml", "test/fixtures/sambocranks.yml", "test/fixtures/schema.rb", "test/test_associations.rb", "test/test_base.rb", "test/test_helper.rb", "passiverecord.gemspec"]
|
17
17
|
s.test_files = ["test/test_associations.rb", "test/test_base.rb", "test/test_helper.rb"]
|
18
18
|
s.add_dependency(%q<activerecord>, [">= 0", "= 1.15.3"])
|
19
19
|
end
|
@@ -23,6 +23,9 @@ end
|
|
23
23
|
#
|
24
24
|
# require 'rubygems'
|
25
25
|
# require 'rake'
|
26
|
+
#
|
27
|
+
# ENV['RUBY_FLAGS'] = "-I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}"
|
28
|
+
#
|
26
29
|
# begin
|
27
30
|
# require 'echoe'
|
28
31
|
#
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Foss < PassiveRecord::Base
|
2
|
+
has_one :candraspouse
|
3
|
+
|
4
|
+
has_many :sambocranks
|
5
|
+
has_many :rhizocables, :through => :sambocranks
|
6
|
+
|
7
|
+
schema :name => String
|
8
|
+
|
9
|
+
create 1, :name => "Hypogenoaular"
|
10
|
+
create 2, :name => "Zaxment"
|
11
|
+
create 3, :name => "Yelpscope"
|
12
|
+
create 4, :name => "Dramisation"
|
13
|
+
create 5, :name => "Codory"
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
2
|
+
|
3
|
+
ActiveRecord::Base.connection.create_table "sambocranks", :force => true do |t|
|
4
|
+
t.column :name, :string
|
5
|
+
t.column :foss_id, :integer
|
6
|
+
end
|
7
|
+
|
8
|
+
ActiveRecord::Base.connection.create_table "rhizocables", :force => true do |t|
|
9
|
+
t.column :name, :string
|
10
|
+
t.column :foss_id, :integer
|
11
|
+
t.column :sambocrank_id, :integer
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveRecord::Base.connection.create_table "candraspouses", :force => true do |t|
|
15
|
+
t.column :name, :string
|
16
|
+
t.column :foss_id, :integer
|
17
|
+
end
|
18
|
+
|
19
|
+
class Sambocrank < ActiveRecord::Base
|
20
|
+
belongs_to :foss
|
21
|
+
has_many :rhizocables
|
22
|
+
end
|
23
|
+
|
24
|
+
class Rhizocable < ActiveRecord::Base
|
25
|
+
belongs_to :foss
|
26
|
+
belongs_to :sambocrank
|
27
|
+
end
|
28
|
+
|
29
|
+
class Candraspouse < ActiveRecord::Base
|
30
|
+
belongs_to :foss
|
31
|
+
end
|
data/test/test_associations.rb
CHANGED
@@ -3,39 +3,40 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
3
3
|
class PassiveRecord::AssociationsTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
create_fixtures :
|
6
|
+
create_fixtures :candraspouses, :sambocranks, :rhizocables
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_should_have_many
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
sambocranks = [
|
11
|
+
Sambocrank.find_by_name("Dakferous"),
|
12
|
+
Sambocrank.find_by_name("Sambaular")
|
13
13
|
]
|
14
|
-
|
15
|
-
assert_equal
|
14
|
+
foss = Foss.find_by_name("Hypogenoaular")
|
15
|
+
assert_equal sambocranks, foss.sambocranks
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_should_have_many_through
|
19
|
-
|
20
|
-
Room.find_by_name("Office"),
|
21
|
-
Room.find_by_name("Restroom")
|
22
|
-
]
|
19
|
+
foss = Foss.find_by_name("Zaxment")
|
23
20
|
|
24
|
-
|
21
|
+
rhizocables = [
|
22
|
+
Rhizocable.find_by_name("Ovumgyps"),
|
23
|
+
Rhizocable.find_by_name("Alfmetric")
|
24
|
+
]
|
25
25
|
|
26
|
-
|
26
|
+
assert_equal rhizocables, foss.rhizocables
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_should_have_one
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
candraspouse = Candraspouse.find_by_name("Maiamorphic")
|
31
|
+
foss = Foss.find_by_name("Zaxment")
|
32
|
+
|
33
|
+
assert_equal candraspouse, foss.candraspouse
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_should_belong_to
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
assert_equal
|
37
|
+
candraspouse = Candraspouse.find_by_name("Eyenium")
|
38
|
+
foss = Foss.find_by_name("Hypogenoaular")
|
39
|
+
|
40
|
+
assert_equal foss, candraspouse.foss
|
40
41
|
end
|
41
42
|
end
|
data/test/test_helper.rb
CHANGED
@@ -13,8 +13,9 @@ Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
|
13
13
|
|
14
14
|
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
15
15
|
|
16
|
+
require 'schema'
|
16
17
|
require 'continents'
|
17
|
-
require '
|
18
|
+
require 'fosses'
|
18
19
|
|
19
20
|
class Test::Unit::TestCase #:nodoc:
|
20
21
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: passiverecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-
|
6
|
+
version: "0.2"
|
7
|
+
date: 2007-11-08 00:00:00 -05:00
|
8
8
|
summary: Pacifying overactive records
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,19 +30,21 @@ authors:
|
|
30
30
|
- Jason L Perry
|
31
31
|
files:
|
32
32
|
- CHANGELOG
|
33
|
-
- Manifest
|
34
|
-
- README
|
35
|
-
- lib/passive_record.rb
|
36
33
|
- lib/passive_record/associations.rb
|
37
34
|
- lib/passive_record/base.rb
|
38
35
|
- lib/passive_record/schema.rb
|
36
|
+
- lib/passive_record.rb
|
37
|
+
- Manifest
|
38
|
+
- README
|
39
|
+
- test/fixtures/candraspouses.yml
|
40
|
+
- test/fixtures/continents.rb
|
41
|
+
- test/fixtures/fosses.rb
|
42
|
+
- test/fixtures/rhizocables.yml
|
43
|
+
- test/fixtures/sambocranks.yml
|
44
|
+
- test/fixtures/schema.rb
|
39
45
|
- test/test_associations.rb
|
40
46
|
- test/test_base.rb
|
41
47
|
- test/test_helper.rb
|
42
|
-
- test/fixtures/continents.rb
|
43
|
-
- test/fixtures/doors.yml
|
44
|
-
- test/fixtures/furniture.rb
|
45
|
-
- test/fixtures/furniture.yml
|
46
48
|
- passiverecord.gemspec
|
47
49
|
test_files:
|
48
50
|
- test/test_associations.rb
|
data/test/fixtures/doors.yml
DELETED
data/test/fixtures/furniture.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
2
|
-
|
3
|
-
ActiveRecord::Base.connection.create_table "furniture", :force => true do |t|
|
4
|
-
t.column :name, :string
|
5
|
-
t.column :room_id, :integer
|
6
|
-
end
|
7
|
-
|
8
|
-
ActiveRecord::Base.connection.create_table "doors", :force => true do |t|
|
9
|
-
t.column :inside_id, :integer
|
10
|
-
t.column :outside_id, :integer
|
11
|
-
end
|
12
|
-
|
13
|
-
Inflector.inflections { |inflect| inflect.uncountable %w( furniture )}
|
14
|
-
|
15
|
-
class Furniture < ActiveRecord::Base
|
16
|
-
belongs_to :room
|
17
|
-
end
|
18
|
-
|
19
|
-
class Door < ActiveRecord::Base
|
20
|
-
belongs_to :inside, :class_name => "Room", :foreign_key => "inside_id"
|
21
|
-
belongs_to :outside, :class_name => "Room", :foreign_key => "outside_id"
|
22
|
-
end
|
23
|
-
|
24
|
-
class Room < PassiveRecord::Base
|
25
|
-
has_many :furniture, :order => :name
|
26
|
-
has_one :light_fixture, :class_name => "Furniture"
|
27
|
-
|
28
|
-
has_many :ins, :class_name => "Door", :foreign_key => "outside_id"
|
29
|
-
has_many :outs, :class_name => "Door", :foreign_key => "inside_id"
|
30
|
-
|
31
|
-
has_many :exits, :through => :outs
|
32
|
-
has_many :entrances, :through => :ins
|
33
|
-
|
34
|
-
schema :name => String
|
35
|
-
|
36
|
-
create 1, :name => "Family Room"
|
37
|
-
create 2, :name => "Kitchen"
|
38
|
-
create 3, :name => "Bedroom"
|
39
|
-
create 4, :name => "Restroom"
|
40
|
-
create 5, :name => "Office"
|
41
|
-
end
|