cuba-sugar 0.1 → 0.1.1
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/README.md +26 -0
- data/lib/cuba/sugar.rb +9 -0
- metadata +12 -1
data/README.md
CHANGED
@@ -34,6 +34,32 @@ Like any other cuba app, but provides:
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
### as_json
|
38
|
+
|
39
|
+
require "cuba"
|
40
|
+
require "cuba/sugar"
|
41
|
+
|
42
|
+
Cuba.use Rack::Session::Cookie
|
43
|
+
|
44
|
+
Cuba.define do
|
45
|
+
on get do
|
46
|
+
on "weather" do
|
47
|
+
# create user
|
48
|
+
as_json do
|
49
|
+
{
|
50
|
+
city: 'La Habana',
|
51
|
+
temperature: '19 °C',
|
52
|
+
pressure: '1014 hPa',
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Contributors
|
60
|
+
------------
|
61
|
+
|
62
|
+
* [bemurphy](https://github.com/bemurphy) (Brendon Murphy)
|
37
63
|
|
38
64
|
Installation
|
39
65
|
------------
|
data/lib/cuba/sugar.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Cuba
|
2
4
|
class Ron
|
3
5
|
# Sugar to do some common response tasks
|
@@ -13,5 +15,12 @@ module Cuba
|
|
13
15
|
res.headers.merge! extra_headers
|
14
16
|
res.write yield if block_given?
|
15
17
|
end
|
18
|
+
|
19
|
+
def as_json(http_code = 200, extra_headers = {})
|
20
|
+
extra_headers["Content-Type"] ||= "application/json"
|
21
|
+
as(http_code, extra_headers) do
|
22
|
+
(yield).to_json if block_given?
|
23
|
+
end
|
24
|
+
end
|
16
25
|
end
|
17
26
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cuba-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- elcuervo
|
@@ -24,6 +24,17 @@ dependencies:
|
|
24
24
|
version: "0"
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
27
38
|
description: Bundled contrib utils to use with cuba
|
28
39
|
email:
|
29
40
|
- yo@brunoaguirre.com
|