lydia 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55cecde25fdd99b6c28cc496d6601b3272dcc98c
4
- data.tar.gz: 07bcf6ebe3fb947b7b4acd65ff6cbe4d5a17b3d9
3
+ metadata.gz: 8c5b7ef25cf346d0026ebcb068c101290b20d358
4
+ data.tar.gz: 7b0f29651e251ec7a231ef5929e57de53322285f
5
5
  SHA512:
6
- metadata.gz: f1537f5c0912af847b86abe97a89cef2eb2c904752cb30acba86c0573fd42a4b4b144344d262f79d5651ef630d6b25b7cce3045d72f06a86444e5d35c55d25cf
7
- data.tar.gz: db7d800dfd02255d7c734d3d00b425da53264880f4671bf3f6e009e9051b030053d28574a660a44289c4f82b0358a93aaddda4861716e69b98b409e7103d8558
6
+ metadata.gz: b2007f3265c8aa888d328d0a054a524603939a5a463661aaa2d704af650c5b23bfafa9b9e34f83a4a91135cb3282890bfa4567e559fcfb1e3be657748f777f52
7
+ data.tar.gz: c0a9e836f9e04d48c096656f563c8cde80bede7e61f0b08411085a6d9496a49169aff9b115d4cdf4eb19083a3cf56d9c0d4e6feb5d0dd9cc584a55a171749fa3
data/README.md CHANGED
@@ -89,6 +89,9 @@ Stand alone example, note that the return type must be in rack standard format,
89
89
  end
90
90
 
91
91
  #### HTTP verbs
92
+ Supports standard HTTP verbs: HEAD GET PATCH PUT POST DELETE OPTIONS.
93
+
94
+ ### DOCUMENTATION IN PROGRESS...
92
95
 
93
96
  #### Parameters
94
97
 
@@ -110,15 +113,46 @@ Stand alone example, note that the return type must be in rack standard format,
110
113
 
111
114
  ### Templates
112
115
 
116
+ Extensive templates support using [tilt](https://github.com/rtomayko/tilt/)
117
+ To render a template simply use the render function:
118
+
119
+ get '/render_erb' do
120
+ render 'template.erb', nil, message: 'template'
121
+ end
122
+
123
+
113
124
  ### Helpers
114
125
 
126
+ #### Redirect
127
+ It's possible to redirect the page using the redirect helper:
128
+
129
+ get '/test' do
130
+ redirect('/new_url')
131
+ end
132
+
133
+ #### Params
134
+ It's possible to read request parameters using params helper:
135
+
136
+ get '/test' do
137
+ params['my_param']
138
+ end
139
+
140
+ #### Content type
141
+ It's possible to force the response return type using content_type helper:
142
+
143
+ get '/test'
144
+ content_type 'application/json'
145
+ 'body'
146
+ end
147
+
115
148
  ## Contributing
116
149
 
117
150
  1. Fork it
118
151
  2. Create your feature branch (`git checkout -b my-new-feature`)
119
- 3. Commit your changes (`git commit -am 'Add some feature'`)
120
- 4. Push to the branch (`git push origin my-new-feature`)
121
- 5. Create new Pull Request
152
+ 3. Add your tests, run rspec and ensure that all tests pass and code coverage is 100%
153
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
154
+ 5. Push to the branch (`git push origin my-new-feature`)
155
+ 6. Create new Pull Request
122
156
 
123
157
  ## License
124
158
 
data/lib/lydia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lydia
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/router_spec.rb CHANGED
@@ -4,9 +4,9 @@ require 'lydia/router'
4
4
 
5
5
  describe "Router" do
6
6
  include Rack::Test::Methods
7
-
7
+
8
8
  class TestRouter < Lydia::Router
9
- get '/' do
9
+ get '/' do
10
10
  get_response('<H1>Hello world!</H1>')
11
11
  end
12
12
 
@@ -16,8 +16,8 @@ describe "Router" do
16
16
 
17
17
  get '/500' do
18
18
  raise StandardError.new('Error!')
19
- end
20
-
19
+ end
20
+
21
21
  head '/request' do get_response('head'); end
22
22
  get '/request' do get_response('get'); end
23
23
  patch '/request' do get_response('patch'); end
@@ -25,7 +25,7 @@ describe "Router" do
25
25
  post '/request' do get_response('post'); end
26
26
  delete '/request' do get_response('delete'); end
27
27
  options '/request' do get_response('options'); end
28
-
28
+
29
29
  namespace '/namespace' do
30
30
  get '/hello' do
31
31
  get_response('Hello from namespace')
@@ -33,20 +33,20 @@ describe "Router" do
33
33
 
34
34
  get %r{/regular$}i do
35
35
  get_response('Regexp inside namespace')
36
- end
37
-
36
+ end
37
+
38
38
  namespace '/nested' do
39
39
  get '/hello' do
40
40
  get_response('Hello from nested namespace')
41
41
  end
42
42
  end
43
-
43
+
44
44
  namespace '/api/v:version' do
45
45
  get '/posts' do
46
46
  get_response("Namespace api version #{request.params[:version]}")
47
47
  end
48
48
  end
49
- end
49
+ end
50
50
 
51
51
  get '/querystring_params' do
52
52
  get_response(request.params['name'])
@@ -54,11 +54,11 @@ describe "Router" do
54
54
 
55
55
  get '/wildcard/*' do
56
56
  get_response('')
57
- end
57
+ end
58
58
 
59
59
  get %r{/regexp$}i do
60
60
  get_response('')
61
- end
61
+ end
62
62
 
63
63
  get '/users/:id/comments/:comment_id/edit' do
64
64
  get_response("#{request.params[:id]}-#{request.params[:comment_id]}")
@@ -67,22 +67,26 @@ describe "Router" do
67
67
  get '/api/v:version/users' do
68
68
  get_response(request.params[:version])
69
69
  end
70
-
70
+
71
+ get '/index.:format' do
72
+ get_response(request.params[:format])
73
+ end
74
+
71
75
  get '/halt' do
72
76
  halt
73
77
  end
74
-
78
+
75
79
  get '/custom_halt' do
76
80
  halt get_response('', 204)
77
- end
78
-
81
+ end
82
+
79
83
  get '/next_route' do
80
84
  next_route
81
85
  end
82
-
86
+
83
87
  get '/next_route' do
84
88
  get_response('Next route works!')
85
- end
89
+ end
86
90
 
87
91
  def get_response(body, status = 200)
88
92
  [status, { 'Content-Type' => 'text/html', 'Content-Length'=> body.length.to_s }, [body]]
@@ -96,18 +100,18 @@ describe "Router" do
96
100
  context 'Status codes' do
97
101
  it 'returns 204' do
98
102
  get '/204'
99
- expect(last_response.status).to eq(204)
103
+ expect(last_response.status).to eq(204)
100
104
  end
101
105
 
102
106
  it 'returns 404' do
103
107
  get '/not_found'
104
- expect(last_response.status).to eq(404)
108
+ expect(last_response.status).to eq(404)
105
109
  end
106
110
 
107
111
  it 'returns 500' do
108
112
  get '/500'
109
- expect(last_response.status).to eq(500)
110
- end
113
+ expect(last_response.status).to eq(500)
114
+ end
111
115
  end
112
116
 
113
117
  context 'Response' do
@@ -117,55 +121,55 @@ describe "Router" do
117
121
  expect(last_response.status).to eq(200)
118
122
  expect(last_response.headers.to_hash).to eq({'Content-Type' => 'text/html', 'Content-Length' => '21'})
119
123
  expect(last_response.body).to eq('<H1>Hello world!</H1>')
120
- end
124
+ end
121
125
  end
122
-
126
+
123
127
  context 'HTTP methods' do
124
128
  it 'HEAD /request' do
125
129
  head '/request'
126
130
  expect(last_response.status).to eq(200)
127
131
  expect(last_response.body).to eq('head')
128
132
  end
129
-
133
+
130
134
  it 'GET /request' do
131
135
  get '/request'
132
136
  expect(last_response.status).to eq(200)
133
137
  expect(last_response.body).to eq('get')
134
138
  end
135
-
139
+
136
140
  it 'PATCH /request' do
137
141
  patch '/request'
138
142
  expect(last_response.status).to eq(200)
139
143
  expect(last_response.body).to eq('patch')
140
144
  end
141
-
145
+
142
146
  it 'PUT /request' do
143
147
  put '/request'
144
148
  expect(last_response.status).to eq(200)
145
149
  expect(last_response.body).to eq('put')
146
150
  end
147
-
151
+
148
152
  it 'POST /request' do
149
153
  post '/request'
150
154
  expect(last_response.status).to eq(200)
151
155
  expect(last_response.body).to eq('post')
152
- end
153
-
156
+ end
157
+
154
158
  it 'DELETE /request' do
155
159
  delete '/request'
156
160
  expect(last_response.status).to eq(200)
157
161
  expect(last_response.body).to eq('delete')
158
- end
159
-
162
+ end
163
+
160
164
  it 'OPTIONS /request' do
161
165
  options '/request'
162
166
  expect(last_response.status).to eq(200)
163
167
  expect(last_response.body).to eq('options')
164
- end
168
+ end
165
169
  end
166
170
 
167
171
  context 'Routing' do
168
-
172
+
169
173
  context 'Namespace' do
170
174
  it 'GET /namespace/hello' do
171
175
  get '/namespace/hello'
@@ -177,19 +181,19 @@ describe "Router" do
177
181
  get '/namespace/nested/hello'
178
182
  expect(last_response.status).to eq(200)
179
183
  expect(last_response.body).to eq('Hello from nested namespace')
180
- end
181
-
184
+ end
185
+
182
186
  it 'GET /namespace/api/v3/posts' do
183
187
  get '/namespace/api/v3/posts'
184
188
  expect(last_response.status).to eq(200)
185
189
  expect(last_response.body).to eq('Namespace api version 3')
186
- end
187
-
190
+ end
191
+
188
192
  it 'GET /namespace/regular' do
189
193
  get '/namespace/regular'
190
194
  expect(last_response.status).to eq(200)
191
195
  end
192
- end
196
+ end
193
197
 
194
198
  context 'Wildcards' do
195
199
  it 'GET wildcard' do
@@ -205,7 +209,7 @@ describe "Router" do
205
209
  it 'GET wildcard/hello' do
206
210
  get '/wildcard/hello'
207
211
  expect(last_response.status).to eq(200)
208
- end
212
+ end
209
213
 
210
214
  it 'GET wildcard/hello/bob' do
211
215
  get '/wildcard/hello/bob'
@@ -219,7 +223,7 @@ describe "Router" do
219
223
  expect(last_response.status).to eq(200)
220
224
  end
221
225
  end
222
-
226
+
223
227
  context 'Next route' do
224
228
  it 'Goto next route' do
225
229
  get '/next_route'
@@ -239,7 +243,13 @@ describe "Router" do
239
243
  get '/api/v2/users'
240
244
  expect(last_response.status).to eq(200)
241
245
  expect(last_response.body).to eq('2')
242
- end
246
+ end
247
+
248
+ it 'GET /index.json' do
249
+ get '/index.json'
250
+ expect(last_response.status).to eq(200)
251
+ expect(last_response.body).to eq('json')
252
+ end
243
253
  end
244
254
 
245
255
  context 'Query string params' do
@@ -247,16 +257,16 @@ describe "Router" do
247
257
  get '/querystring_params', { name: 'bob' }
248
258
  expect(last_response.status).to eq(200)
249
259
  expect(last_response.body).to eq('bob')
250
- end
260
+ end
251
261
  end
252
-
253
- context 'Route not valid' do
262
+
263
+ context 'Route not valid' do
254
264
  it 'returns ArgumentError' do
255
265
  expect {
256
266
  class WrongRoute < Lydia::Router
257
- get Object do
267
+ get Object do
258
268
  end
259
- end
269
+ end
260
270
  }.to raise_error(ArgumentError)
261
271
  end
262
272
  end
@@ -268,35 +278,35 @@ describe "Router" do
268
278
  it 'responds to request' do
269
279
  expect(router).to respond_to(:request)
270
280
  end
271
-
281
+
272
282
  it 'responds to response' do
273
283
  expect(router).to respond_to(:response)
274
- end
284
+ end
275
285
 
276
286
  it 'responds to env' do
277
287
  expect(router).to respond_to(:env)
278
- end
288
+ end
279
289
  end
280
-
290
+
281
291
  context 'Halt' do
282
292
  it 'returns 500 (default halt)' do
283
293
  get '/halt'
284
294
  expect(last_response.status).to eq(500)
285
295
  expect(last_response.body).to include('halted')
286
296
  end
287
-
297
+
288
298
  it 'returns 204 (custom halt)' do
289
299
  get '/custom_halt'
290
300
  expect(last_response.status).to eq(204)
291
301
  expect(last_response.body).to eq('')
292
- end
302
+ end
293
303
  end
294
304
 
295
- context 'Class methods' do
305
+ context 'Class methods' do
296
306
  it 'is initialized' do
297
307
  get '/'
298
308
  expect(last_response.status).to eq(200)
299
- end
309
+ end
300
310
  end
301
-
311
+
302
312
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lydia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mirko Mignini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler