ananke 1.0.2 → 1.0.3
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/lib/ananke/helpers.rb +14 -8
- data/lib/ananke/routing.rb +28 -17
- data/lib/version.rb +1 -1
- data/spec/lib/error_spec.rb +48 -0
- metadata +22 -20
data/lib/ananke/helpers.rb
CHANGED
@@ -55,24 +55,30 @@ module Ananke
|
|
55
55
|
|
56
56
|
def define_repository_call(mod, method_name)
|
57
57
|
inputs = mod.method(method_name).parameters
|
58
|
-
repository_name = mod.name.split('::').last
|
59
|
-
call_def = "def self.call_#{repository_name}_#{method_name}(params)"
|
58
|
+
repository_name = mod.name.split('::').last.downcase
|
59
|
+
call_def = "def self.call_#{repository_name}_#{method_name}(params)\n"
|
60
60
|
case inputs.length
|
61
61
|
when 0
|
62
|
-
call_def << "#{mod}.send(:#{method_name})"
|
62
|
+
call_def << " #{mod}.send(:#{method_name})\n"
|
63
63
|
when 1
|
64
|
-
call_def << "
|
64
|
+
call_def << " param = params[:key] ? params[:key] : params.values.first\n"
|
65
|
+
call_def << " #{mod}.send(:#{method_name}, param)\n"
|
65
66
|
else
|
66
67
|
input_array = []
|
67
68
|
inputs.each{|i| input_array << "params[:#{i[1]}]"}
|
68
|
-
call_def << "#{mod}.send(:#{method_name}, #{input_array.join(',')})"
|
69
|
+
call_def << " #{mod}.send(:#{method_name}, #{input_array.join(',')})\n"
|
69
70
|
end
|
70
71
|
call_def << "end"
|
71
72
|
Ananke.send(:eval, call_def)
|
72
73
|
end
|
73
74
|
|
74
|
-
def repository_call(mod, method_name, params)
|
75
|
-
repository_name = mod.name.split('::').last
|
76
|
-
|
75
|
+
def repository_call(mod, method_name, params = {})
|
76
|
+
repository_name = mod.name.split('::').last.downcase
|
77
|
+
begin
|
78
|
+
return Ananke.send("call_#{repository_name}_#{method_name}", params), 200
|
79
|
+
rescue StandardError => error
|
80
|
+
raise if !error.message.start_with?(method_name.to_s)
|
81
|
+
return error.message, 400
|
82
|
+
end
|
77
83
|
end
|
78
84
|
end
|
data/lib/ananke/routing.rb
CHANGED
@@ -59,9 +59,7 @@ module Ananke
|
|
59
59
|
out(:error, "Repository for #{path} not found")
|
60
60
|
return
|
61
61
|
end
|
62
|
-
if @id.empty?
|
63
|
-
out :info, "No Id specified for #{path}"
|
64
|
-
end
|
62
|
+
out :info, "No Id specified for #{path}" if @id.empty?
|
65
63
|
key = @id[:key]
|
66
64
|
fields = @fields
|
67
65
|
link_list = @link_list
|
@@ -70,18 +68,23 @@ module Ananke
|
|
70
68
|
|
71
69
|
#===========================GET/ID=============================
|
72
70
|
build_route mod, :one, :get, "/#{path}/:#{key}" do
|
73
|
-
|
74
|
-
|
71
|
+
new_params = collect_params(params)
|
72
|
+
param_missing!(key) if new_params[key].nil?
|
75
73
|
|
76
|
-
|
74
|
+
obj, obj_status = repository_call(mod, :one, new_params)
|
75
|
+
error obj_status, obj if obj_status >= 400
|
76
|
+
|
77
|
+
status obj_status
|
77
78
|
make_response(path, mod, link_list, link_to_list, obj, key)
|
78
79
|
end
|
79
80
|
|
80
81
|
#===========================GET================================
|
81
82
|
build_route mod, :all, :get, "/#{path}/?" do
|
82
|
-
|
83
|
+
|
84
|
+
obj, obj_status = repository_call(mod, :all)
|
85
|
+
error obj_status, obj if obj_status >= 400
|
83
86
|
|
84
|
-
status
|
87
|
+
status obj_status
|
85
88
|
make_response(path, mod, link_list, link_to_list, obj, key)
|
86
89
|
end
|
87
90
|
|
@@ -90,8 +93,9 @@ module Ananke
|
|
90
93
|
new_params = collect_params(params)
|
91
94
|
status, message = validate(fields, new_params)
|
92
95
|
error status, message unless status.nil?
|
93
|
-
|
94
|
-
obj = repository_call(mod, :add, new_params)
|
96
|
+
|
97
|
+
obj, obj_status = repository_call(mod, :add, new_params)
|
98
|
+
error obj_status, obj if obj_status >= 400
|
95
99
|
|
96
100
|
status 201
|
97
101
|
make_response(path, mod, link_list, link_to_list, obj, key)
|
@@ -104,9 +108,10 @@ module Ananke
|
|
104
108
|
status, message = validate(fields, new_params)
|
105
109
|
error status, message unless status.nil?
|
106
110
|
|
107
|
-
obj = repository_call(mod, :edit, new_params)
|
111
|
+
obj, obj_status = repository_call(mod, :edit, new_params)
|
112
|
+
error obj_status, obj if obj_status >= 400
|
108
113
|
|
109
|
-
status
|
114
|
+
status obj_status
|
110
115
|
make_response(path, mod, link_list, link_to_list, obj, key)
|
111
116
|
end
|
112
117
|
|
@@ -116,9 +121,13 @@ module Ananke
|
|
116
121
|
|
117
122
|
#===========================DELETE=============================
|
118
123
|
build_route mod, :delete, :delete, "/#{path}/:#{key}" do
|
119
|
-
|
120
|
-
|
121
|
-
|
124
|
+
new_params = collect_params(params)
|
125
|
+
param_missing!(key) if new_params[key].nil?
|
126
|
+
|
127
|
+
obj, obj_status = repository_call(mod, :delete, new_params)
|
128
|
+
error obj_status, obj if obj_status >= 400
|
129
|
+
|
130
|
+
status obj_status
|
122
131
|
end
|
123
132
|
|
124
133
|
build_route mod, :delete, :delete, "/#{path}/?" do
|
@@ -135,10 +144,12 @@ module Ananke
|
|
135
144
|
new_params = collect_params(params)
|
136
145
|
param_missing!(:key) if inputs.length == 1 && new_params[:key].nil?
|
137
146
|
|
138
|
-
obj = repository_call(mod, r[:name], new_params)
|
147
|
+
obj, obj_status = repository_call(mod, r[:name], new_params)
|
148
|
+
error obj_status, obj if obj_status >= 400
|
149
|
+
|
139
150
|
obj_list = obj.class == Array ? obj : [obj]
|
140
151
|
|
141
|
-
status
|
152
|
+
status obj_status
|
142
153
|
make_response(path, mod, link_list, link_to_list, obj_list, key).gsub("\"/#{path}/\"", "\"#{request.path}\"")
|
143
154
|
end
|
144
155
|
end
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require './lib/ananke'
|
3
|
+
|
4
|
+
describe 'Resource Route-For' do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
include Ananke
|
7
|
+
|
8
|
+
def app
|
9
|
+
Sinatra::Base
|
10
|
+
end
|
11
|
+
|
12
|
+
it """
|
13
|
+
should return a code 400 for an error raised in the Repository that has a message that starts with the method name
|
14
|
+
""" do
|
15
|
+
module Repository
|
16
|
+
module Errors
|
17
|
+
def self.exception400(id)
|
18
|
+
raise 'exception400 - Some Exception'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
route :errors do
|
23
|
+
route_for :exception400
|
24
|
+
end
|
25
|
+
|
26
|
+
get "/errors/exception400/1"
|
27
|
+
check_status(400)
|
28
|
+
last_response.body.should == 'exception400 - Some Exception'
|
29
|
+
end
|
30
|
+
|
31
|
+
it """
|
32
|
+
should return a code 500 for an error raised in the Repository
|
33
|
+
""" do
|
34
|
+
module Repository
|
35
|
+
module Errors
|
36
|
+
def self.exception500(id)
|
37
|
+
raise 'Some Exception'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
route :errors do
|
42
|
+
route_for :exception500
|
43
|
+
end
|
44
|
+
|
45
|
+
get "/errors/exception500/1"
|
46
|
+
check_status(500)
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ananke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Andries Coetzee
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-23 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -100,25 +100,26 @@ extra_rdoc_files:
|
|
100
100
|
- README.rdoc
|
101
101
|
files:
|
102
102
|
- lib/ananke.rb
|
103
|
+
- lib/version.rb
|
103
104
|
- lib/ananke/settings.rb
|
104
|
-
- lib/ananke/helpers.rb
|
105
105
|
- lib/ananke/linking.rb
|
106
|
-
- lib/ananke/serialize.rb
|
107
|
-
- lib/ananke/validation.rb
|
108
106
|
- lib/ananke/routing.rb
|
109
|
-
- lib/
|
110
|
-
-
|
111
|
-
-
|
107
|
+
- lib/ananke/validation.rb
|
108
|
+
- lib/ananke/helpers.rb
|
109
|
+
- lib/ananke/serialize.rb
|
112
110
|
- spec/dumping.rb
|
113
111
|
- spec/cov_adapter.rb
|
114
|
-
- spec/lib/json_spec.rb
|
115
112
|
- spec/lib/ananke_spec.rb
|
116
|
-
- spec/lib/route_for_spec.rb
|
117
|
-
- spec/lib/out_spec.rb
|
118
113
|
- spec/lib/validation_spec.rb
|
119
|
-
- spec/lib/
|
114
|
+
- spec/lib/out_spec.rb
|
115
|
+
- spec/lib/json_spec.rb
|
120
116
|
- spec/lib/link_to_spec.rb
|
117
|
+
- spec/lib/route_for_spec.rb
|
118
|
+
- spec/lib/error_spec.rb
|
119
|
+
- spec/lib/linked_spec.rb
|
121
120
|
- spec/spec_helper.rb
|
121
|
+
- spec/call_chain.rb
|
122
|
+
- spec/nice_formatter.rb
|
122
123
|
- Gemfile
|
123
124
|
- Rakefile
|
124
125
|
- README.rdoc
|
@@ -129,7 +130,7 @@ licenses: []
|
|
129
130
|
post_install_message: |
|
130
131
|
**************************************************
|
131
132
|
|
132
|
-
Thank you for installing ananke-1.0.
|
133
|
+
Thank you for installing ananke-1.0.3
|
133
134
|
|
134
135
|
Please be sure to look at README.rdoc to see what might have changed
|
135
136
|
since the last release and how to use this GEM.
|
@@ -158,17 +159,18 @@ rubyforge_project:
|
|
158
159
|
rubygems_version: 1.5.0
|
159
160
|
signing_key:
|
160
161
|
specification_version: 3
|
161
|
-
summary: ananke-1.0.
|
162
|
+
summary: ananke-1.0.3
|
162
163
|
test_files:
|
163
|
-
- spec/nice_formatter.rb
|
164
|
-
- spec/call_chain.rb
|
165
164
|
- spec/dumping.rb
|
166
165
|
- spec/cov_adapter.rb
|
167
|
-
- spec/lib/json_spec.rb
|
168
166
|
- spec/lib/ananke_spec.rb
|
169
|
-
- spec/lib/route_for_spec.rb
|
170
|
-
- spec/lib/out_spec.rb
|
171
167
|
- spec/lib/validation_spec.rb
|
172
|
-
- spec/lib/
|
168
|
+
- spec/lib/out_spec.rb
|
169
|
+
- spec/lib/json_spec.rb
|
173
170
|
- spec/lib/link_to_spec.rb
|
171
|
+
- spec/lib/route_for_spec.rb
|
172
|
+
- spec/lib/error_spec.rb
|
173
|
+
- spec/lib/linked_spec.rb
|
174
174
|
- spec/spec_helper.rb
|
175
|
+
- spec/call_chain.rb
|
176
|
+
- spec/nice_formatter.rb
|