cryx-g5k 0.2.6 → 0.2.7
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 +1 -1
- data/lib/g5k.rb +16 -0
- data/spec/g5k_spec.rb +23 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/g5k.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# Subdirs are not automatically loaded. Users must explicitly require them.
|
2
2
|
|
3
3
|
module G5K
|
4
|
+
class Api
|
5
|
+
class << self
|
6
|
+
# must be a hash of RestClient resources
|
7
|
+
attr_accessor :registered_apis
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.select(api_name, api_version = nil, api_uri = nil)
|
11
|
+
if (registered_apis && api = (registered_apis[api_name] || registered_apis[api_name.to_s] || registered_apis[api_name.to_sym]))
|
12
|
+
api = api["/#{api_version}"] if api_version
|
13
|
+
api = api[api_uri] if api_uri
|
14
|
+
api
|
15
|
+
else
|
16
|
+
raise ArgumentError, "The API #{api_name} is not available."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
4
20
|
end
|
5
21
|
|
6
22
|
unless [].respond_to?(:group_by) || [].respond_to?(:index_by)
|
data/spec/g5k_spec.rb
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'restclient'
|
2
3
|
|
3
|
-
describe "
|
4
|
+
describe "G5K::Api" do
|
5
|
+
|
6
|
+
it "should find the api if the api name is a string" do
|
7
|
+
db_api = mock('restclient resource')
|
8
|
+
G5K::Api.registered_apis = {:db => db_api}
|
9
|
+
G5K::Api.select('db').should == db_api
|
10
|
+
end
|
11
|
+
it "should find the api if the api name is a symbol" do
|
12
|
+
db_api = mock('restclient resource')
|
13
|
+
G5K::Api.registered_apis = {'db' => db_api}
|
14
|
+
G5K::Api.select(:db).should == db_api
|
15
|
+
end
|
16
|
+
it "should raise an ArgumentError if the API is not registered" do
|
17
|
+
db_api = mock('restclient resource')
|
18
|
+
G5K::Api.registered_apis = {'db' => db_api}
|
19
|
+
lambda{G5K::Api.select(:whatever)}.should raise_error ArgumentError
|
20
|
+
end
|
21
|
+
it "should add the version and the URI complement at the end of the URI if they are given" do
|
22
|
+
db_api = RestClient::Resource.new('https://localhost:4444')
|
23
|
+
G5K::Api.registered_apis = {'db' => db_api}
|
24
|
+
G5K::Api.select(:db, '1.0-stable', '/sites/rennes').url.should == 'https://localhost:4444/1.0-stable/sites/rennes'
|
25
|
+
end
|
4
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryx-g5k
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Rohr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|