cyrax 0.3.5 → 0.3.6

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWRlYWZmNDkxMWJiNGI4NzNiM2FmZWY5YWViMTk4Y2YwY2VhYzQ3NA==
4
+ ZDUwZDAwMmI2ZDA0ODYwMmRjMGFhMzZmN2EyMzBmYjc4N2QyNWQxZA==
5
5
  data.tar.gz: !binary |-
6
- MTEwZjQ4OGQ4YmFjZWMwNDQyOTdiNTUxOGMxZTFkZTJmMjM5MmQ0ZA==
6
+ MGIyYmJhMWJlMjIyN2NlYmI3ZWVkYzBiMGY0MzMwNGFmMWU2MGEzMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjRhYWI0ZmZlNmY1NDBlYTQ0MmI0NDAxOTdhZTFlMjdlMmYwYzY3MjkzMDc4
10
- ZWZiNDc3OTRmMTI3N2NjODZkN2VkZGQwZmZmMGI1MjM4ZmY4OTVjNWMwYjBi
11
- YWI3ZGExN2UyYjdjOGVlMDNkNmQ2ODlhZDFjYjc3Y2FiMjBhZGI=
9
+ N2Q3YTIyOTM2MzdkNzRiZjhiYTRjNzY3MGFiNDQ0NTU5ZjBiYjcxYzk4ODli
10
+ MzgyMDZkMWZmOGRmZTNmZTJmOGNmNzZjNTc5MTNiMDFiMDBkNjhjZjQwZjlh
11
+ NDg5Zjg1ZTQwMDZmNjBlODIxMzdhZmY1MmIwZmU3MzdjNzViNWQ=
12
12
  data.tar.gz: !binary |-
13
- NTI1NTFmOWVlYzBmYzFkODMzZGNiYzMxODgzMjk4YmMzZjlmYzhiZGUwMjgz
14
- ZDUxZTlkYThjNzJmYWJlMmE2M2ZlNzNhMGVmYTAwZjhhYjdhZDUyMjBhZmU5
15
- ZmM1M2NjZjI4YTNhNTU4YWU1NTExNDk2Y2NjNmQxZTliZGMwNTU=
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)
@@ -1,9 +1,11 @@
1
1
  class Cyrax::Response
2
- attr_accessor :message, :errors, :assignments, :result, :resource_name
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
- result.as_json(*args)
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)
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droidlabs