medea 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/medea/jason_base.rb +6 -8
- data/lib/medea/jasondeferredquery.rb +3 -0
- data/lib/medea/jasonobject.rb +8 -1
- data/lib/medea/templates/search.template +5 -4
- data/lib/medea/version.rb +2 -2
- data/spec/jason_object_spec.rb +11 -0
- metadata +2 -2
data/lib/medea/jason_base.rb
CHANGED
@@ -5,13 +5,6 @@ module Medea
|
|
5
5
|
inheritable_attributes :owned
|
6
6
|
@owned = false
|
7
7
|
|
8
|
-
|
9
|
-
#returns the JasonObject by directly querying the URL
|
10
|
-
#if mode is :lazy, we return a GHOST, if mode is :eager, we return a STALE JasonObject
|
11
|
-
def self.get_by_key(key, mode=:eager)
|
12
|
-
return self.new key, mode
|
13
|
-
end
|
14
|
-
|
15
8
|
#the resolve method takes a key and returns the JasonObject that has that key
|
16
9
|
#This is useful when you have the key, but not the class
|
17
10
|
def self.resolve(key, mode=:lazy)
|
@@ -88,6 +81,10 @@ module Medea
|
|
88
81
|
@__jason_parent_list = value
|
89
82
|
end
|
90
83
|
|
84
|
+
def jason_timestamp
|
85
|
+
@__jason_timestamp
|
86
|
+
end
|
87
|
+
|
91
88
|
def delete! cascade=false
|
92
89
|
#TODO: Put this into some kind of async method or have JasonDB able to set flags on many records at once
|
93
90
|
#This will be REALLY REALLY slowww!
|
@@ -121,11 +118,12 @@ module Medea
|
|
121
118
|
def load_from_jasondb
|
122
119
|
#because this object might be owned by another, we need to search by key.
|
123
120
|
#not passing a format to the query is a shortcut to getting just the object.
|
124
|
-
url =
|
121
|
+
url = to_url
|
125
122
|
|
126
123
|
response = RestClient.get url
|
127
124
|
@__jason_data = JSON.parse response
|
128
125
|
@__jason_etag = response.headers[:etag]
|
126
|
+
@__jason_timestamp = response.headers[:timestamp]
|
129
127
|
@__jason_state = :stale
|
130
128
|
end
|
131
129
|
|
@@ -153,6 +153,9 @@ module Medea
|
|
153
153
|
if result[k].has_key?("HTTP_X_PARENT") && result[k]["HTTP_X_PARENT"] != ""
|
154
154
|
item.jason_parent_key = result[k]["HTTP_X_PARENT"]
|
155
155
|
end
|
156
|
+
if result[k].has_key?("TIMESTAMP")
|
157
|
+
item.instance_variable_set :@__jason_timestamp, result[k]["TIMESTAMP"]
|
158
|
+
end
|
156
159
|
self.contents << item
|
157
160
|
end
|
158
161
|
end
|
data/lib/medea/jasonobject.rb
CHANGED
@@ -51,6 +51,12 @@ module Medea
|
|
51
51
|
end
|
52
52
|
#end query interface
|
53
53
|
|
54
|
+
#returns the JasonObject by directly querying the URL
|
55
|
+
#if mode is :lazy, we return a GHOST, if mode is :eager, we return a STALE JasonObject
|
56
|
+
def self.get_by_key(key, mode=:eager)
|
57
|
+
return self.new key, mode
|
58
|
+
end
|
59
|
+
|
54
60
|
#"flexihash" access interface
|
55
61
|
def []=(key, value)
|
56
62
|
if @attachments.keys.include? key.to_sym
|
@@ -211,7 +217,8 @@ module Medea
|
|
211
217
|
#save successful!
|
212
218
|
#store the new eTag for this object
|
213
219
|
#puts response.raw_headers
|
214
|
-
|
220
|
+
@__jason_etag = response.headers[:Etag]
|
221
|
+
@__jason_timestamp = response.headers[:timestamp]
|
215
222
|
else
|
216
223
|
raise "#{method.to_s.upcase} failed! Could not persist changes"
|
217
224
|
end
|
@@ -15,13 +15,14 @@
|
|
15
15
|
"RELATIVE_VERSION":"[%RELATIVE_VERSION%]",
|
16
16
|
"RECID":"[%RECID%]",
|
17
17
|
"RECNO":"[%RECNO%]",
|
18
|
+
"TIMESTAMP":"[%TIMESTAMP%]",
|
18
19
|
"ETag":"[%ETag%]",
|
19
20
|
"HTTP_X_SCHEMA":"[%HTTP_X_SCHEMA%]",
|
20
21
|
"HTTP_X_GENERATED_PASSWORD":"[%HTTP_X_GENERATED_PASSWORD%]",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
"HTTP_X_CLASS":"[%HTTP_X_CLASS%]",
|
23
|
+
"HTTP_X_LIST":"[%HTTP_X_LIST%]",
|
24
|
+
"HTTP_X_KEY":"[%HTTP_X_KEY%]",
|
25
|
+
"HTTP_X_PARENT":"[%HTTP_X_PARENT%]",
|
25
26
|
"CONTENT":[%CONTENT%]
|
26
27
|
}[%COMMA%]
|
27
28
|
%item%-->
|
data/lib/medea/version.rb
CHANGED
data/spec/jason_object_spec.rb
CHANGED
@@ -81,4 +81,15 @@ describe "JasonObject" do
|
|
81
81
|
@user.stub(:save).and_return false
|
82
82
|
(@user.update_attributes({})).should eq(false)
|
83
83
|
end
|
84
|
+
|
85
|
+
it "should provide access to its timestamp from JasonDB" do
|
86
|
+
@user.save!
|
87
|
+
@user.jason_timestamp.should_not be_nil
|
88
|
+
t = @user.jason_timestamp
|
89
|
+
@user.name = "Smithy"
|
90
|
+
@user.save!
|
91
|
+
user2 = User.get_by_key(@user.jason_key)
|
92
|
+
user2.jason_timestamp.should_not be_nil
|
93
|
+
user2.jason_timestamp.should be > t
|
94
|
+
end
|
84
95
|
end
|