medea 0.2.29 → 0.2.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/medea.rb +1 -0
- data/lib/medea/jasondb.rb +1 -0
- data/lib/medea/jasondeferredquery.rb +13 -17
- data/lib/medea/jasonlistproperty.rb +20 -13
- data/lib/medea/jasonobject.rb +12 -18
- data/lib/medea/version.rb +1 -1
- data/lib/testjdq.rb +1 -0
- data/lib/testjlp.rb +2 -1
- data/lib/testmeta.rb +1 -0
- data/lib/testsublist.rb +1 -1
- metadata +4 -4
data/lib/medea.rb
CHANGED
data/lib/medea/jasondb.rb
CHANGED
@@ -2,6 +2,7 @@ module JasonDB
|
|
2
2
|
#jason_url here doesn't include the http[s]:// part, but does include the domain and a trailing '/'
|
3
3
|
#( so it's "rest.jasondb.com/<domain>/" )
|
4
4
|
def JasonDB::db_auth_url mode=:secure
|
5
|
+
return "https://michael:password@rest.jasondb.com/medea-dev/"
|
5
6
|
config = Rails.configuration.database_configuration[Rails.env]
|
6
7
|
|
7
8
|
user = config["user"]
|
@@ -1,18 +1,15 @@
|
|
1
1
|
module Medea
|
2
|
-
class
|
2
|
+
class JasonDeferredQuery
|
3
3
|
require 'rest_client'
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
attr_accessor :time_limit, :result_format, :type, :time_limit, :state, :contents, :filters
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
self.type =
|
10
|
-
self.filters =
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
self.result_format = format
|
15
|
-
self.time_limit = 0
|
8
|
+
def initialize opts={}
|
9
|
+
self.type = opts[:class] if opts[:class]
|
10
|
+
self.filters = opts[:filters] if opts[:filters]
|
11
|
+
self.result_format = opts[:format] ? opts[:format] : :search
|
12
|
+
self.time_limit = opts[:time_limit] ? opts[:time_limit] : 0
|
16
13
|
self.state = :prefetch
|
17
14
|
self.contents = []
|
18
15
|
end
|
@@ -62,9 +59,10 @@ module Medea
|
|
62
59
|
def to_url
|
63
60
|
url = "#{JasonDB::db_auth_url}@#{self.time_limit}.#{self.result_format}?"
|
64
61
|
filter_array = []
|
62
|
+
unsafe = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
|
65
63
|
self.filters.each do |name, val|
|
66
64
|
if not val
|
67
|
-
filter_array << name.to_s
|
65
|
+
filter_array << URI.escape(name.to_s, unsafe)
|
68
66
|
next
|
69
67
|
else
|
70
68
|
#FILTER's value is a hash (to avoid dupes)
|
@@ -74,10 +72,10 @@ module Medea
|
|
74
72
|
val.each do |field ,value|
|
75
73
|
if value.is_a? Array
|
76
74
|
value.each do |i|
|
77
|
-
filter_array << "#{name.to_s}=#{
|
75
|
+
filter_array << URI.escape("#{name.to_s}=#{field}:#{i}", unsafe)
|
78
76
|
end
|
79
77
|
else
|
80
|
-
filter_array << "#{name.to_s}=#{
|
78
|
+
filter_array << URI.escape("#{name.to_s}=#{field.to_s}:#{value.to_s}", unsafe)
|
81
79
|
end
|
82
80
|
end
|
83
81
|
end
|
@@ -112,7 +110,7 @@ module Medea
|
|
112
110
|
end
|
113
111
|
#end array interface
|
114
112
|
|
115
|
-
def execute_query
|
113
|
+
def execute_query content=true
|
116
114
|
#hit the URL
|
117
115
|
#fill self.contents with :ghost versions of JasonObjects
|
118
116
|
begin
|
@@ -123,10 +121,8 @@ module Medea
|
|
123
121
|
result.keys.each do |k|
|
124
122
|
if k =~ /^[0-9]+$/
|
125
123
|
#this is a result! get the key
|
126
|
-
|
127
|
-
|
128
|
-
item = type.new($2, :lazy)
|
129
|
-
if result[k].has_key?("CONTENT") && result[k]["CONTENT"] != ""
|
124
|
+
item = type.new(result[k]["HTTP_X_KEY"], :lazy)
|
125
|
+
if content && result[k].has_key?("CONTENT") && result[k]["CONTENT"] != ""
|
130
126
|
item.instance_variable_set(:@__jason_data, result[k]["CONTENT"])
|
131
127
|
item.instance_variable_set(:@__jason_state, :stale)
|
132
128
|
end
|
@@ -6,14 +6,18 @@ module Medea
|
|
6
6
|
attr_accessor :list_name, :parent, :list_type
|
7
7
|
|
8
8
|
def initialize parent, list_name, list_class, list_type
|
9
|
-
|
9
|
+
super :class => list_class,
|
10
|
+
:format => :search,
|
11
|
+
:filters => {
|
12
|
+
:VERSION0 => nil,
|
13
|
+
:FILTER => {:HTTP_X_LIST => list_name}}
|
14
|
+
|
15
|
+
self.filters[:FILTER][:HTTP_X_CLASS] = list_class.name if list_type == :value
|
10
16
|
@list_name = list_name
|
11
|
-
@list_type = list_type
|
12
17
|
@parent = parent
|
13
|
-
@result_format = :search
|
14
|
-
@time_limit = 0
|
15
18
|
@state = :prefetch
|
16
19
|
@contents = []
|
20
|
+
@list_type = list_type
|
17
21
|
end
|
18
22
|
|
19
23
|
def method_missing name, *args, &block
|
@@ -39,11 +43,9 @@ module Medea
|
|
39
43
|
member.jason_parent_list = @list_name
|
40
44
|
elsif @list_type == :reference
|
41
45
|
|
42
|
-
|
43
|
-
url = "#{JasonDB::db_auth_url}#{@type.name}/#{@parent.jason_key}/#{@list_name}/#{member.jason_key}"
|
46
|
+
url = "#{JasonDB::db_auth_url}#{@parent.class.name}/#{@parent.jason_key}/#{@list_name}/#{member.jason_key}"
|
44
47
|
post_headers = {
|
45
48
|
:content_type => 'application/json',
|
46
|
-
"X-CLASS" => @list_name.to_s,
|
47
49
|
"X-KEY" => member.jason_key,
|
48
50
|
"X-PARENT" => @parent.jason_key,
|
49
51
|
"X-LIST" => @list_name.to_s
|
@@ -106,26 +108,31 @@ module Medea
|
|
106
108
|
@state = :prefetch
|
107
109
|
end
|
108
110
|
|
111
|
+
def execute_query
|
112
|
+
#call super, but don't use the content to populate if this is a reference list
|
113
|
+
content = @list_type == :reference ? false : true
|
114
|
+
super content
|
115
|
+
end
|
116
|
+
|
117
|
+
|
109
118
|
def to_url
|
110
119
|
url = "#{JasonDB::db_auth_url}@#{@time_limit}.#{@result_format}?"
|
111
120
|
params = ["VERSION0"]
|
112
|
-
|
113
|
-
params << "FILTER=HTTP_X_CLASS:#{@list_name.to_s}"
|
121
|
+
params << "FILTER=HTTP_X_LIST:#{@list_name.to_s}"
|
114
122
|
|
115
123
|
if @parent.is_a? JasonObject
|
116
124
|
params << "FILTER=HTTP_X_PARENT:#{@parent.jason_key}"
|
117
125
|
else # @parent.is_a? JasonListProperty ##(or DeferredQuery?)
|
118
126
|
#we can get the insecure url here, because it will be resolved and executed at JasonDB - on a secure subnet.
|
119
127
|
|
120
|
-
#subquery = "<%@LANGUAGE=\"URL\" #{@parent.to_url}%>"
|
121
128
|
#puts " = Fetching subquery stupidly. (#{@parent.to_url})"
|
122
|
-
|
129
|
+
@parent.result_format = :keylist
|
123
130
|
subquery = (RestClient.get @parent.to_url).strip
|
124
131
|
#puts " = Result: #{subquery}"
|
125
|
-
params <<
|
132
|
+
params << "FILTER={HTTP_X_PARENT:#{subquery}}"
|
126
133
|
end
|
127
134
|
|
128
|
-
url << params.join("&")
|
135
|
+
url << URI.escape(params.join("&"), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
129
136
|
end
|
130
137
|
end
|
131
138
|
end
|
data/lib/medea/jasonobject.rb
CHANGED
@@ -24,7 +24,7 @@ module Medea
|
|
24
24
|
#create a JasonDeferredQuery with no conditions, other than HTTP_X_CLASS=self.name
|
25
25
|
#if mode is set to :eager, we create the JasonDeferredQuery, invoke it's execution and then return it
|
26
26
|
def JasonObject.all(mode=:lazy)
|
27
|
-
JasonDeferredQuery.new self
|
27
|
+
JasonDeferredQuery.new :class => self, :filters => {:FILTER => {:HTTP_X_CLASS => self}}
|
28
28
|
end
|
29
29
|
|
30
30
|
#returns the JasonObject by directly querying the URL
|
@@ -38,7 +38,8 @@ module Medea
|
|
38
38
|
#find_by_<property>(value)
|
39
39
|
#Will return a JasonDeferredQuery for this class with the appropriate data filter set
|
40
40
|
def JasonObject.method_missing(name, *args, &block)
|
41
|
-
|
41
|
+
|
42
|
+
q = all
|
42
43
|
if name.to_s =~ /^members_of$/
|
43
44
|
#use the type and key of the first arg (being a JasonObject)
|
44
45
|
return q.members_of args[0]
|
@@ -57,7 +58,7 @@ module Medea
|
|
57
58
|
#the resolve method takes a key and returns the JasonObject that has that key
|
58
59
|
#This is useful when you have the key, but not the class
|
59
60
|
def JasonObject.resolve(key, mode=:lazy)
|
60
|
-
q = JasonDeferredQuery.new
|
61
|
+
q = JasonDeferredQuery.new :filters => {:FILTER => {:HTTP_X_KEY => key}}
|
61
62
|
q.filters[:FILTER] ||= {}
|
62
63
|
q.filters[:FILTER][:HTTP_X_KEY] = key
|
63
64
|
resp = JSON.parse(RestClient.get(q.to_url))
|
@@ -183,7 +184,6 @@ module Medea
|
|
183
184
|
payload = self.to_json
|
184
185
|
post_headers = {
|
185
186
|
:content_type => 'application/json',
|
186
|
-
|
187
187
|
"X-KEY" => self.jason_key,
|
188
188
|
"X-CLASS" => self.class.name
|
189
189
|
#also want to add the eTag here!
|
@@ -194,12 +194,12 @@ module Medea
|
|
194
194
|
if self.class.owned
|
195
195
|
#the parent object needs to be defined!
|
196
196
|
raise "#{self.class.name} cannot be saved without setting a parent and list!" unless self.jason_parent && self.jason_parent_list
|
197
|
-
post_headers["X-PARENT"] = self.jason_parent.jason_key
|
198
|
-
#url = "#{JasonDB::db_auth_url}#{self.jason_parent.class.name}/#{self.jason_parent.jason_key}/#{self.jason_parent_list}/#{self.jason_key}"
|
199
|
-
post_headers["X-LIST"] = self.jason_parent_list
|
200
|
-
#override the class to be the list name. Much simpler to search on.
|
201
|
-
post_headers["X-CLASS"] = self.jason_parent_list
|
202
197
|
end
|
198
|
+
|
199
|
+
post_headers["X-PARENT"] = self.jason_parent.jason_key if self.jason_parent
|
200
|
+
post_headers["X-LIST"] = self.jason_parent_list if self.jason_parent_list
|
201
|
+
|
202
|
+
|
203
203
|
url = JasonDB::db_auth_url + self.class.name + "/" + self.jason_key
|
204
204
|
|
205
205
|
#puts "Posted to JasonDB!"
|
@@ -241,15 +241,9 @@ module Medea
|
|
241
241
|
url = "#{JasonDB::db_auth_url}@0.content?"
|
242
242
|
params = [
|
243
243
|
"VERSION0",
|
244
|
-
"FILTER=HTTP_X_KEY:#{self.jason_key}"
|
245
|
-
|
246
|
-
|
247
|
-
if not self.class.owned
|
248
|
-
#if the class is owned, we don't want to filter by class name (X-CLASS will be the list name)
|
249
|
-
#if it isn't owned, it is safe to filter by X-CLASS
|
250
|
-
#if this item is "had" rather than owned, we MUST filter by class, otherwise we get the references.
|
251
|
-
params << "FILTER=HTTP_X_CLASS:#{self.class.name}"
|
252
|
-
end
|
244
|
+
"FILTER=HTTP_X_KEY:#{self.jason_key}",
|
245
|
+
"FILTER=HTTP_X_CLASS:#{self.class.name}"
|
246
|
+
]
|
253
247
|
|
254
248
|
url << params.join("&")
|
255
249
|
#url = "#{JasonDB::db_auth_url}#{self.class.name}/#{self.jason_key}"
|
data/lib/medea/version.rb
CHANGED
data/lib/testjdq.rb
CHANGED
data/lib/testjlp.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
$: << "~/Projects/Medea/lib"
|
2
|
+
require 'rubygems'
|
2
3
|
require 'medea'
|
3
4
|
|
4
5
|
class Person < Medea::JasonObject
|
5
6
|
has_many :followees, Person
|
6
7
|
end
|
7
8
|
|
8
|
-
p = Person.get_by_key "
|
9
|
+
p = Person.get_by_key "pa76b65a2-ba64-4cf0-8b37-7ad6a30ee8db"
|
9
10
|
|
10
11
|
puts p.followees.to_url
|
11
12
|
puts p.followees.count
|
data/lib/testmeta.rb
CHANGED
data/lib/testsublist.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
$: << "~/Projects/Medea/lib"
|
2
|
+
require 'rubygems'
|
2
3
|
require 'medea'
|
3
4
|
|
4
5
|
class Message < Medea::JasonObject; end
|
@@ -17,7 +18,6 @@ u2.name = "George"
|
|
17
18
|
u2.save!
|
18
19
|
|
19
20
|
u1.followees.add! u2
|
20
|
-
u1.followees.add! (User.get_by_key "p438639000")
|
21
21
|
u1.followees.add! u1
|
22
22
|
|
23
23
|
m1 = Message.new
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: medea
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 43
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 30
|
10
|
+
version: 0.2.30
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Jensen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-06 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|