mattly-exegesis 0.0.7 → 0.0.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.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 7
4
+ :patch: 8
@@ -74,7 +74,10 @@ module Exegesis
74
74
  alias :_rev :rev
75
75
  alias_method :document_save, :save
76
76
 
77
+ attr_accessor :parent
78
+
77
79
  def save
80
+ raise ChildError, "cannot save if a parent is set" if parent
78
81
  set_timestamps if respond_to?(:set_timestamps)
79
82
  if respond_to?(:set_unique_id) && id.nil?
80
83
  @unique_id_attempt = 0
@@ -129,15 +132,16 @@ module Exegesis
129
132
 
130
133
  with = klass == Time ? :parse : :new
131
134
  casted = klass.send with, value
135
+ casted.parent = self if casted.respond_to?(:parent)
132
136
  casted
133
137
  end
134
138
 
135
139
  def load_reference ids
136
- raise ArgumentError, "a database is required for loading a reference" unless database
140
+ raise ArgumentError, "a database is required for loading a reference" unless database || (parent && parent.database)
137
141
  if ids.is_a?(Array)
138
- ids.map {|val| Exegesis::Document.instantiate(database.get(val)) }
142
+ ids.map {|val| Exegesis::Document.instantiate((database || parent && parent.database).get(val)) }
139
143
  else
140
- Exegesis::Document.instantiate(database.get(ids))
144
+ Exegesis::Document.instantiate((database || parent && parent.database).get(ids))
141
145
  end
142
146
  end
143
147
 
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
2
 
3
- class Foo < Exegesis::Document; end
3
+ class Foo < Exegesis::Document
4
+ expose :ref, :as => :reference
5
+ end
4
6
  class Bar < Exegesis::Document; end
5
7
 
6
8
  class WithDefault < Exegesis::Document
@@ -104,12 +106,15 @@ class ExegesisDocumentClassDefinitionsTest < Test::Unit::TestCase
104
106
 
105
107
  expect { @obj.castee.class.will == Foo }
106
108
  expect { @obj.castee['foo'].will == 'foo' }
109
+ expect { @obj.castee.parent.will == @obj }
107
110
 
108
111
  expect { @obj.castees.class.will == Array }
109
112
  expect { @obj.castees[0].class.will == Foo }
110
113
  expect { @obj.castees[0]['foo'].will == 'foo' }
114
+ expect { @obj.castees[0].parent.will == @obj }
111
115
  expect { @obj.castees[1].class.will == Bar }
112
116
  expect { @obj.castees[1]['foo'].will == 'bar' }
117
+ expect { @obj.castees[1].parent.will == @obj }
113
118
  end
114
119
 
115
120
  context "when as time" do
@@ -149,6 +154,7 @@ class ExegesisDocumentClassDefinitionsTest < Test::Unit::TestCase
149
154
  @obj = Exposer.new(:other_doc => "other_doc", :other_docs => ["other_docs_1", "other_docs_2"])
150
155
  @obj.database = @db
151
156
  end
157
+
152
158
  context "when the document exists" do
153
159
  before do
154
160
  @db.bulk_save([
@@ -183,6 +189,17 @@ class ExegesisDocumentClassDefinitionsTest < Test::Unit::TestCase
183
189
  expect { lambda{@obj.other_doc}.will raise_error(RestClient::ResourceNotFound) }
184
190
  expect { lambda{@obj.other_docs}.will raise_error(RestClient::ResourceNotFound) }
185
191
  end
192
+
193
+ context "when the doucment has a parent" do
194
+ before do
195
+ @obj.castee = Foo.new({})
196
+ @obj.castee.ref = 'other_doc'
197
+ @obj.save
198
+ @db.save_doc({'.kind' => 'Foo', '_id' => 'other_doc'})
199
+ end
200
+
201
+ expect { @obj.castee.ref.rev.will == @db.get('other_doc')['_rev'] }
202
+ end
186
203
  end
187
204
 
188
205
  context "without a database present" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattly-exegesis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Lyon