eazypi 0.0.2 → 0.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.
- checksums.yaml +4 -4
- data/lib/eazypi/api_controller.rb +16 -0
- data/lib/eazypi/operation.rb +7 -0
- data/lib/eazypi/response.rb +6 -0
- data/lib/eazypi/responses.rb +5 -0
- data/lib/eazypi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe47c3c3c7c8c3ac25c0d67311957fb2672599ea81f48e6247f82b9fae6710b
|
4
|
+
data.tar.gz: 436ec6c096a12482add4ac1a0245b4c555e254fd3be329ba9549e6b1422a1154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f849fdc4f64b2471955dcf1b8517e6bd445d2285b646384c6081b6aa9ffb87d78e9be72a093c4731436ea6fd4340561a2b1aa89886cdb3e53f0c8007bfd704d6
|
7
|
+
data.tar.gz: 62e8ba592f52624d36bedba28e96f463956c6ae3cb16e1aa2d89acfc060459bc897d2034bdfa8e7423b7222104f0f4bca0acdbe4729358d821abc9d3cf5a91ce
|
@@ -5,6 +5,7 @@ module Eazypi
|
|
5
5
|
module ApiController
|
6
6
|
def self.included(base)
|
7
7
|
base.instance_variable_set(:@operations, [])
|
8
|
+
base.include(InstanceMethods)
|
8
9
|
base.extend(ClassMethods)
|
9
10
|
end
|
10
11
|
|
@@ -53,5 +54,20 @@ module Eazypi
|
|
53
54
|
controller_method_name
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
# Instance methods to be used in your own API controller
|
59
|
+
module InstanceMethods
|
60
|
+
def respond_with(object, status: :ok)
|
61
|
+
response_type = @current_operation.response_for_response_code(status)
|
62
|
+
|
63
|
+
response_object_type = response_type.object_type_for_content_type
|
64
|
+
|
65
|
+
if response_object_type.nil?
|
66
|
+
render json: nil, status: status
|
67
|
+
else
|
68
|
+
render json: response_type.object_type_for_content_type.new(object).to_json, status: status
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
56
72
|
end
|
57
73
|
end
|
data/lib/eazypi/operation.rb
CHANGED
@@ -44,11 +44,18 @@ module Eazypi
|
|
44
44
|
@responses.add_response(status_code, &block)
|
45
45
|
end
|
46
46
|
|
47
|
+
def response_for_response_code(response_code)
|
48
|
+
response_code = Rack::Utils::SYMBOL_TO_STATUS_CODE[response_code] if response_code.is_a?(Symbol)
|
49
|
+
|
50
|
+
@responses.response_for_response_code(response_code)
|
51
|
+
end
|
52
|
+
|
47
53
|
def render(&block)
|
48
54
|
@renderer = block
|
49
55
|
end
|
50
56
|
|
51
57
|
def call(controller)
|
58
|
+
controller.instance_variable_set(:@current_operation, self)
|
52
59
|
controller.instance_exec(&@renderer)
|
53
60
|
end
|
54
61
|
|
data/lib/eazypi/response.rb
CHANGED
@@ -9,6 +9,7 @@ module Eazypi
|
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@content = {}
|
12
|
+
@object_type = {}
|
12
13
|
|
13
14
|
super
|
14
15
|
end
|
@@ -23,6 +24,11 @@ module Eazypi
|
|
23
24
|
end
|
24
25
|
|
25
26
|
@content[content_type] = media_type
|
27
|
+
@object_type[content_type] = schema
|
28
|
+
end
|
29
|
+
|
30
|
+
def object_type_for_content_type(content_type = "application/json")
|
31
|
+
@object_type[content_type]
|
26
32
|
end
|
27
33
|
|
28
34
|
def collect_components(**kwargs)
|
data/lib/eazypi/responses.rb
CHANGED
@@ -14,6 +14,11 @@ module Eazypi
|
|
14
14
|
@responses[status_code.to_s] = response
|
15
15
|
end
|
16
16
|
|
17
|
+
def response_for_response_code(response_code)
|
18
|
+
# Future improvement could be partial match
|
19
|
+
@responses[response_code.to_s]
|
20
|
+
end
|
21
|
+
|
17
22
|
def collect_components(**kwargs)
|
18
23
|
@responses.each_value do |response|
|
19
24
|
response.collect_components(**kwargs)
|
data/lib/eazypi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eazypi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Samson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|