medea 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/medea/jasondb.rb +36 -0
- data/lib/medea/version.rb +5 -1
- data/lib/medea.rb +1 -0
- data/spec/medea_spec.rb +49 -0
- metadata +5 -11
data/lib/medea/jasondb.rb
CHANGED
@@ -24,3 +24,39 @@ module JasonDB
|
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
27
|
+
|
28
|
+
module Medea
|
29
|
+
def Medea::setup_templates
|
30
|
+
template_dir = "templates"
|
31
|
+
name_pattern = /([A-Za-z]+)\.template/
|
32
|
+
headers = {:content_type => 'text/plain',
|
33
|
+
'X-VERSION' => TEMPLATE_VERSION}
|
34
|
+
curr_version = TEMPLATE_VERSION.split "."
|
35
|
+
Dir.glob(File.expand_path(File.join(template_dir, "*.template"))).select do |file|
|
36
|
+
#for each template, we need to post it to ..#{filename}:html_template
|
37
|
+
file =~ name_pattern
|
38
|
+
template_path = "#{JasonDB::db_auth_url}..#{$1}:html_template"
|
39
|
+
|
40
|
+
#but,check the version first...
|
41
|
+
begin
|
42
|
+
r = RestClient.get template_path
|
43
|
+
if r.code == 200 && r.headers[:http_x_version]
|
44
|
+
version = r.headers[:http_x_version].split(".")
|
45
|
+
version.each_index do |i|
|
46
|
+
if version[i] < curr_version[i]
|
47
|
+
RestClient.post template_path, File.read(file), headers
|
48
|
+
break
|
49
|
+
elsif version[i] > curr_version[i]
|
50
|
+
raise "The remote templates are newer than the local ones! Update your gem!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
next
|
54
|
+
end
|
55
|
+
|
56
|
+
rescue RestClient::ResourceNotFound
|
57
|
+
#do nothing, it just means that the templates aren't uploaded yet.
|
58
|
+
end
|
59
|
+
RestClient.post template_path, File.read(file), headers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/medea/version.rb
CHANGED
data/lib/medea.rb
CHANGED
data/spec/medea_spec.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rspec"
|
2
|
+
|
3
|
+
describe "Medea Framework" do
|
4
|
+
it "should install templates if they aren't there" do
|
5
|
+
resp = mock("Response").as_null_object
|
6
|
+
RestClient.stub(:get).and_return resp
|
7
|
+
RestClient.stub(:post).and_return resp
|
8
|
+
resp.stub(:code).and_return 404
|
9
|
+
resp.stub(:headers).and_return({})
|
10
|
+
|
11
|
+
RestClient.should_receive(:post)
|
12
|
+
Medea::setup_templates
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should install templates if the template version is newer" do
|
16
|
+
resp = mock("Response").as_null_object
|
17
|
+
RestClient.stub(:get).and_return resp
|
18
|
+
RestClient.stub(:post).and_return resp
|
19
|
+
resp.stub(:code).and_return 200
|
20
|
+
resp.stub(:headers).and_return({:http_x_version => "0.1.0"})
|
21
|
+
|
22
|
+
RestClient.should_receive(:post)
|
23
|
+
Medea::setup_templates
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not install templates if they are up to date" do
|
27
|
+
resp = mock("Response").as_null_object
|
28
|
+
RestClient.stub(:get).and_return resp
|
29
|
+
RestClient.stub(:post).and_return resp
|
30
|
+
resp.stub(:code).and_return 200
|
31
|
+
resp.stub(:headers).and_return({:http_x_version => Medea::TEMPLATE_VERSION})
|
32
|
+
|
33
|
+
RestClient.should_not_receive(:post)
|
34
|
+
Medea::setup_templates
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise an error if the remote version is newer" do
|
38
|
+
resp = mock("Response").as_null_object
|
39
|
+
RestClient.stub(:get).and_return resp
|
40
|
+
RestClient.stub(:post).and_return resp
|
41
|
+
resp.stub(:code).and_return 200
|
42
|
+
#version 999.0.0 is pretty much guaranteed to always be a newer version
|
43
|
+
resp.stub(:headers).and_return({:http_x_version => "999.0.0"})
|
44
|
+
|
45
|
+
RestClient.should_not_receive(:post)
|
46
|
+
expect{Medea::setup_templates}.to raise_error(RuntimeError)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
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: 29
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
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: 2011-01-
|
17
|
+
date: 2011-01-13 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"
|
@@ -68,7 +64,6 @@ dependencies:
|
|
68
64
|
requirements:
|
69
65
|
- - ">="
|
70
66
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
67
|
segments:
|
73
68
|
- 0
|
74
69
|
version: "0"
|
@@ -102,6 +97,7 @@ files:
|
|
102
97
|
- medea.gemspec
|
103
98
|
- spec/jason_object_spec.rb
|
104
99
|
- spec/list_properties_spec.rb
|
100
|
+
- spec/medea_spec.rb
|
105
101
|
- spec/spec_helper.rb
|
106
102
|
has_rdoc: true
|
107
103
|
homepage: ""
|
@@ -117,7 +113,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
113
|
requirements:
|
118
114
|
- - ">="
|
119
115
|
- !ruby/object:Gem::Version
|
120
|
-
hash: 3
|
121
116
|
segments:
|
122
117
|
- 0
|
123
118
|
version: "0"
|
@@ -126,7 +121,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
121
|
requirements:
|
127
122
|
- - ">="
|
128
123
|
- !ruby/object:Gem::Version
|
129
|
-
hash: 3
|
130
124
|
segments:
|
131
125
|
- 0
|
132
126
|
version: "0"
|