passiverecord 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.2. has_many :through is in the house.
2
+
1
3
  v0.1. Different subclasses of PassiveRecord can now use the same keys safely.
2
4
 
3
5
  v0.0.2. Switching to Echoe for gem packaging and removing the end-user dependency for Hoe
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(*args)
271
- ActiveRecord::Base.send(:reflect_on_association, *args)
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
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Passiverecord-0.1
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.1"
8
- s.date = %q{2007-10-03}
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", "Manifest", "README", "lib/passive_record.rb", "lib/passive_record/associations.rb", "lib/passive_record/base.rb", "lib/passive_record/schema.rb", "test/test_associations.rb", "test/test_base.rb", "test/test_helper.rb", "test/fixtures/continents.rb", "test/fixtures/doors.yml", "test/fixtures/furniture.rb", "test/fixtures/furniture.yml", "passiverecord.gemspec"]
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,13 @@
1
+ ---
2
+ eyenium:
3
+ id: 1
4
+ name: Eyenium
5
+ foss_id: 1
6
+ maiamorphic:
7
+ id: 2
8
+ name: Maiamorphic
9
+ foss_id: 2
10
+ brevikonameter:
11
+ id: 3
12
+ name: Brevikonameter
13
+ foss_id: 5
@@ -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,16 @@
1
+ ---
2
+ ovumgyps:
3
+ id: 1
4
+ name: Ovumgyps
5
+ foss_id: 2
6
+ sambocrank_id: 3
7
+ alfmetric:
8
+ id: 2
9
+ name: Alfmetric
10
+ foss_id: 2
11
+ sambocrank_id: 3
12
+ hypoverbitis:
13
+ id: 3
14
+ name: Hypoverbitis
15
+ foss_id: 1
16
+ sambocrank_id: 2
@@ -0,0 +1,13 @@
1
+ ---
2
+ dakferous:
3
+ id: 1
4
+ name: Dakferous
5
+ foss_id: 1
6
+ sambaular:
7
+ id: 2
8
+ name: Sambaular
9
+ foss_id: 1
10
+ osteonazi:
11
+ id: 3
12
+ name: Osteonazi
13
+ foss_id: 2
@@ -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
@@ -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 :doors, :furniture
6
+ create_fixtures :candraspouses, :sambocranks, :rhizocables
7
7
  end
8
8
 
9
9
  def test_should_have_many
10
- furniture = [
11
- Furniture.find_by_name("Couch"),
12
- Furniture.find_by_name("Ottoman")
10
+ sambocranks = [
11
+ Sambocrank.find_by_name("Dakferous"),
12
+ Sambocrank.find_by_name("Sambaular")
13
13
  ]
14
- room = Room.find_by_name("Family Room")
15
- assert_equal furniture, room.furniture
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
- rooms = [
20
- Room.find_by_name("Office"),
21
- Room.find_by_name("Restroom")
22
- ]
19
+ foss = Foss.find_by_name("Zaxment")
23
20
 
24
- room = Room.find_by_name("Family Room")
21
+ rhizocables = [
22
+ Rhizocable.find_by_name("Ovumgyps"),
23
+ Rhizocable.find_by_name("Alfmetric")
24
+ ]
25
25
 
26
- # assert_equal room, room.exits
26
+ assert_equal rhizocables, foss.rhizocables
27
27
  end
28
28
 
29
29
  def test_should_have_one
30
- lamp = Furniture.find_by_name("Ott-lite")
31
- room = Room.find_by_name("Office")
32
- assert_equal lamp, room.light_fixture
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
- lamp = Furniture.find_by_name("Ott-lite")
37
- room = Room.find_by_name("Office")
38
-
39
- assert_equal room, lamp.room
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
@@ -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 'furniture'
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.1"
7
- date: 2007-10-03 00:00:00 -04:00
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
@@ -1,9 +0,0 @@
1
- ---
2
- office:
3
- id: 1
4
- inside_id: 5
5
- outside_id: 1
6
- restroom:
7
- id: 2
8
- inside_id: 4
9
- outside_id: 1
@@ -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
@@ -1,13 +0,0 @@
1
- ---
2
- couch:
3
- id: 1
4
- name: Couch
5
- room_id: 1
6
- ottoman:
7
- id: 2
8
- name: Ottoman
9
- room_id: 1
10
- ottlite:
11
- id: 3
12
- name: Ott-lite
13
- room_id: 5