cyrax 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDUwZDAwMmI2ZDA0ODYwMmRjMGFhMzZmN2EyMzBmYjc4N2QyNWQxZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGIyYmJhMWJlMjIyN2NlYmI3ZWVkYzBiMGY0MzMwNGFmMWU2MGEzMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2Q3YTIyOTM2MzdkNzRiZjhiYTRjNzY3MGFiNDQ0NTU5ZjBiYjcxYzk4ODli
|
10
|
+
MzgyMDZkMWZmOGRmZTNmZTJmOGNmNzZjNTc5MTNiMDFiMDBkNjhjZjQwZjlh
|
11
|
+
NDg5Zjg1ZTQwMDZmNjBlODIxMzdhZmY1MmIwZmU3MzdjNzViNWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDBkMWQwY2Y5ZWRkMWMwYWUyZTYyZDlhZmMyMzU5OTUzMjEyY2RlZjdmMDk0
|
14
|
+
ZDVkMGYyNDBmMTM5ZDE0NzQ2MDU3ZDIzMzgwMDA1YTQ5MTI0ZGU0MmU5MGJj
|
15
|
+
ZDcxN2NhMmE5MzBhZGMxZDM1YTZmNzRlNWIxNjhmOTgxZjVmZWU=
|
@@ -47,7 +47,7 @@ module Cyrax::Extensions
|
|
47
47
|
options = {serializer: serializer_class}.merge(options)
|
48
48
|
end
|
49
49
|
result = Cyrax::Presenter.present(result, options)
|
50
|
-
response = Cyrax::Response.new(name, result)
|
50
|
+
response = Cyrax::Response.new(name, result, options)
|
51
51
|
response.message = @_message
|
52
52
|
response.errors = @_errors
|
53
53
|
response.assignments = @_assignments
|
@@ -14,7 +14,15 @@ module Cyrax::ControllerHelper
|
|
14
14
|
result = response.result
|
15
15
|
result = result.to_model if result.respond_to?(:to_model)
|
16
16
|
|
17
|
-
super(result, default_options.merge(options || {}))
|
17
|
+
super(result, default_options.merge(options || {})) do |format|
|
18
|
+
format.json do
|
19
|
+
if result.respond_to?(:errors) && result.errors.present?
|
20
|
+
render json: { errors: result.errors }
|
21
|
+
else
|
22
|
+
render json: response.as_json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
18
26
|
else
|
19
27
|
super(*args)
|
20
28
|
end
|
@@ -20,14 +20,6 @@ module Cyrax::Presenters
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def as_json(*args)
|
24
|
-
if options[:serializer]
|
25
|
-
options[:serializer].new(presented_collection).serialize
|
26
|
-
else
|
27
|
-
presented_collection.as_json
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
23
|
def method_missing(method, *args, &block)
|
32
24
|
return super unless collection.respond_to?(method)
|
33
25
|
collection.send(method, *args, &block)
|
data/lib/cyrax/response.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
class Cyrax::Response
|
2
|
-
attr_accessor :message, :errors, :assignments,
|
2
|
+
attr_accessor :message, :errors, :assignments,
|
3
|
+
:result, :resource_name, :options
|
3
4
|
|
4
|
-
def initialize(resource_name, result)
|
5
|
+
def initialize(resource_name, result, options)
|
5
6
|
@resource_name = resource_name
|
6
7
|
@result = result
|
8
|
+
@options = options
|
7
9
|
@message = nil
|
8
10
|
@errors = []
|
9
11
|
@assignments = {}
|
@@ -40,7 +42,11 @@ class Cyrax::Response
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def as_json(*args)
|
43
|
-
|
45
|
+
if options[:serializer]
|
46
|
+
options[:serializer].new(result).serialize
|
47
|
+
else
|
48
|
+
result.as_json
|
49
|
+
end
|
44
50
|
end
|
45
51
|
|
46
52
|
def method_missing(method, *args, &block)
|
data/lib/cyrax/version.rb
CHANGED