dm-is-temporal 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -137,7 +137,6 @@ TODO
137
137
  ------
138
138
 
139
139
  + MyClass.update (update all records for a model) doesn't work
140
- + Bi-directional Temporal Associations
141
140
  + Temporal Property pattern (i.e. multiple independent temporal properties per class)
142
141
  + Bi-temporality
143
142
  + Add a config flag that enables an error to be raised when attempting to rewrite existing versions
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ begin
4
4
 
5
5
  Jeweler::Tasks.new do |gem|
6
6
  gem.name = 'dm-is-temporal'
7
- gem.version = '0.4.0'
7
+ gem.version = '0.5.0'
8
8
  gem.summary = 'DataMapper plugin implementing temporal patterns'
9
9
  gem.description = gem.summary
10
10
  gem.email = 'jpkutner [a] gmail [d] com'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -292,11 +292,18 @@ module DataMapper
292
292
  @temporal_list_model = temporal_list_model
293
293
  @name = name
294
294
  @context = context
295
+
296
+ @bidirectional_method = DataMapper::Inflector.singularize(
297
+ DataMapper::Inflector.tableize(base_object.class.name.split('::').last))
295
298
  end
296
299
 
297
300
  def <<(x)
298
301
  new_model = @temporal_list_model.create(:updated_at => @context, @name => x)
302
+ if x.respond_to?("#{@bidirectional_method}=")
303
+ x.send("#{@bidirectional_method}=", @base_object)
304
+ end
299
305
  @base_object.send(@temporal_list_name) << new_model
306
+ @list << x
300
307
  end
301
308
 
302
309
  def clear
@@ -367,14 +374,16 @@ module DataMapper
367
374
  raise "Unsupported method"
368
375
  end
369
376
 
370
- def pop(n=nil)
377
+ def pop
371
378
  temporal = @base_object.send(@temporal_list_name).last
372
379
  temporal.deleted_at = @context
373
380
  temporal.send(@name)
374
381
  end
375
382
 
376
383
  def push(*obj)
377
- raise "Unsupported method"
384
+ obj.each do |o|
385
+ self.<< o
386
+ end
378
387
  end
379
388
 
380
389
  def rehject!
data/spec/assoc_spec.rb CHANGED
@@ -7,8 +7,15 @@ module Assoc
7
7
  property :id, Serial
8
8
  property :baz, String
9
9
 
10
- # todo bi-direction temporal relationships
11
- # belongs_to :my_model
10
+ belongs_to :my_model
11
+ end
12
+
13
+ class ThreeFoobar
14
+ include DataMapper::Resource
15
+ property :id, Serial
16
+ property :version, DateTime
17
+ belongs_to :foobar
18
+ belongs_to :my_model_three
12
19
  end
13
20
 
14
21
  class MyModel
@@ -32,12 +39,24 @@ module Assoc
32
39
  has n, :foobazes, 'Foobar'
33
40
  end
34
41
  end
42
+
43
+ class MyModelThree
44
+ include DataMapper::Resource
45
+
46
+ property :id, Serial
47
+
48
+ is_temporal do
49
+ property :name, String
50
+ has n, :three_foobars
51
+ end
52
+ end
35
53
  end
36
54
 
37
55
  describe DataMapper::Is::Temporal do
38
56
 
39
57
  before(:all) do
40
- DataMapper.setup(:default, "sqlite3::memory:")
58
+ # DataMapper.setup(:default, "sqlite3::memory:")
59
+ DataMapper.setup(:default, "postgres://localhost/dm_is_temporal")
41
60
  DataMapper.setup(:test, "sqlite3::memory:")
42
61
  end
43
62
 
@@ -60,6 +79,8 @@ describe DataMapper::Is::Temporal do
60
79
  subject.foobars.should include(f)
61
80
 
62
81
  subject.instance_eval { self.temporal_foobars.size.should == 1}
82
+
83
+ f.my_model.should == subject
63
84
  end
64
85
 
65
86
  it "adds a couple Foobars at different times" do
@@ -259,5 +280,25 @@ describe DataMapper::Is::Temporal do
259
280
  subject.instance_eval { self.temporal_foobazes.size.should == 2}
260
281
  end
261
282
  end
283
+
284
+ context "with join class" do
285
+ subject do
286
+ Assoc::MyModelThree.create
287
+ end
288
+
289
+ it "adds a Foobar at the current time" do
290
+ f = Assoc::Foobar.create(:baz => "hello")
291
+ join = Assoc::ThreeFoobar.create(:foobar => f)
292
+ subject.three_foobars << join
293
+ subject.save
294
+ subject.three_foobars.size.should == 1
295
+ subject.three_foobars.should include(join)
296
+
297
+ subject.instance_eval { self.temporal_three_foobars.size.should == 1}
298
+
299
+ x = DataMapper.repository(:default).adapter.select("select * from assoc_my_model_three_temporal_three_foobars")
300
+ puts "x=#{x.inspect}"
301
+ end
302
+ end
262
303
  end
263
304
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dm-is-temporal
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joe Kutner
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-11 00:00:00 -05:00
13
+ date: 2011-05-12 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency