medea 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.13
1
+ 0.2.14
@@ -1,20 +1,35 @@
1
1
  module JasonDB
2
- #jason_url here doesn't include the http[s]:// part, but does include the domain and a trailing '/'
3
- #( so it's "rest.jasondb.com/<domain>/" )
2
+ def JasonDB::class_exists? class_name
3
+ const = Module.const_get(class_name)
4
+ return const.is_a? Class
5
+ rescue NameError
6
+ return false
7
+ end
4
8
 
5
- def JasonDB::db_auth_url mode=:secure
9
+ #jason_url here doesn't include the http[s]:// part, but does include the domain and a trailing '/'
10
+ #( so it's "rest.jasondb.com/<domain>/" )
11
+ def JasonDB::db_auth_url mode=:secure
12
+ #check to see if this is a Rails environment
13
+ if class_exists? "Rails"
6
14
  config = Rails.configuration.database_configuration[Rails.env]
7
- user = config["user"]
8
- topic = config["topic"]
9
- password = config["password"]
10
- if config["jason_host"]
11
- host = config["jason_host"]
12
- else
13
- host = "rest.jasondb.com"
14
- end
15
- protocol = "http"
16
- protocol << "s" if mode == :secure
17
- "#{protocol}://#{user}:#{password}@#{host}/#{topic}/"
15
+ else
16
+ #if not, use some defaults for testing medea.
17
+ config = {"user" => "michael",
18
+ "topic" => "medea-test",
19
+ "password" => "password"}
18
20
  end
19
21
 
22
+ user = config["user"]
23
+ topic = config["topic"]
24
+ password = config["password"]
25
+ if config["jason_host"]
26
+ host = config["jason_host"]
27
+ else
28
+ host = "rest.jasondb.com"
29
+ end
30
+ protocol = "http"
31
+ protocol << "s" if mode == :secure
32
+ "#{protocol}://#{user}:#{password}@#{host}/#{topic}/"
33
+ end
34
+
20
35
  end
@@ -100,7 +100,7 @@ module Medea
100
100
  end
101
101
  #end array interface
102
102
 
103
- def execute_query
103
+ def execute_query content=false
104
104
  #hit the URL
105
105
  #fill self.contents with :ghost versions of JasonObjects
106
106
  begin
@@ -114,7 +114,7 @@ module Medea
114
114
  /\/([^\/]*)\/([^\/]*)$/.match result[k]["POST_TO"]
115
115
  #$1 is the class name, $2 is the key
116
116
  item = type.new($2, :lazy)
117
- if result[k].has_key? "CONTENT"
117
+ if result[k].has_key? "CONTENT" && content
118
118
  item.instance_variable_set(:@__jason_data, result[k]["CONTENT"])
119
119
  item.instance_variable_set(:@__jason_state, :stale)
120
120
  end
@@ -10,7 +10,7 @@ module Medea
10
10
  @list_name = list_name
11
11
  @list_type = list_type
12
12
  @parent = parent
13
- @result_format = :json
13
+ @result_format = :search
14
14
  @time_limit = 0
15
15
  @state = :prefetch
16
16
  @contents = []
@@ -43,7 +43,7 @@ module Medea
43
43
  url = "#{JasonDB::db_auth_url}#{@type.name}/#{@parent.jason_key}/#{@list_name}/#{member.jason_key}"
44
44
  post_headers = {
45
45
  :content_type => 'application/json',
46
- "X-CLASS" => @type.name,
46
+ "X-CLASS" => @list_name.to_s,
47
47
  "X-KEY" => member.jason_key,
48
48
  "X-PARENT" => @parent.jason_key,
49
49
  "X-LIST" => @list_name.to_s
@@ -81,7 +81,7 @@ module Medea
81
81
  url = "#{JasonDB::db_auth_url}@#{@time_limit}.#{@result_format}?"
82
82
  params = ["VERSION0"]
83
83
 
84
- params << "FILTER=HTTP_X_CLASS:#{@type.name}"
84
+ params << "FILTER=HTTP_X_CLASS:#{@list_name.to_s}"
85
85
 
86
86
  if @parent.is_a? JasonObject
87
87
  params << "FILTER=HTTP_X_PARENT:#{@parent.jason_key}"
@@ -152,12 +152,10 @@ module Medea
152
152
  #the parent object needs to be defined!
153
153
  raise "#{self.class.name} cannot be saved without setting a parent and list!" unless self.jason_parent && self.jason_parent_list
154
154
  post_headers["X-PARENT"] = self.jason_parent.jason_key
155
- url = "#{JasonDB::db_auth_url}#{self.jason_parent.class.name}/#{self.jason_parent.jason_key}/#{self.jason_parent_list}/#{self.jason_key}"
155
+ #url = "#{JasonDB::db_auth_url}#{self.jason_parent.class.name}/#{self.jason_parent.jason_key}/#{self.jason_parent_list}/#{self.jason_key}"
156
156
  post_headers["X-LIST"] = self.jason_parent_list
157
- else
158
- url = JasonDB::db_auth_url + self.class.name + "/" + self.jason_key
159
157
  end
160
-
158
+ url = JasonDB::db_auth_url + self.class.name + "/" + self.jason_key
161
159
 
162
160
  #puts "Posted to JasonDB!"
163
161
 
@@ -195,14 +193,15 @@ module Medea
195
193
  def load
196
194
  #because this object might be owned by another, we need to search by key.
197
195
  #not passing a format to the query is a shortcut to getting just the object.
198
- url = "#{JasonDB::db_auth_url}@0.content?"
199
- params = [
200
- "VERSION0",
201
- "FILTER=HTTP_X_CLASS:#{self.class.name}",
202
- "FILTER=HTTP_X_KEY:#{self.jason_key}"
203
- ]
204
-
205
- url << params.join("&")
196
+ #url = "#{JasonDB::db_auth_url}@0.content?"
197
+ #params = [
198
+ # "VERSION0",
199
+ # #"FILTER=HTTP_X_CLASS:#{self.class.name}",
200
+ # "FILTER=HTTP_X_KEY:#{self.jason_key}"
201
+ #]
202
+
203
+ #url << params.join("&")
204
+ url = "#{JasonDB::db_auth_url}#{self.class.name}/#{self.jason_key}"
206
205
 
207
206
  #puts " = Retrieving #{self.class.name} at #{url}"
208
207
  response = RestClient.get url
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medea
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 13
10
- version: 0.2.13
8
+ - 14
9
+ version: 0.2.14
11
10
  platform: ruby
12
11
  authors:
13
12
  - Michael Jensen
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-24 00:00:00 +11:00
17
+ date: 2010-12-29 00:00:00 +11:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -93,7 +89,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
89
  requirements:
94
90
  - - ">="
95
91
  - !ruby/object:Gem::Version
96
- hash: 3
97
92
  segments:
98
93
  - 0
99
94
  version: "0"
@@ -102,7 +97,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
97
  requirements:
103
98
  - - ">="
104
99
  - !ruby/object:Gem::Version
105
- hash: 3
106
100
  segments:
107
101
  - 0
108
102
  version: "0"