invalid_model-serializer 0.1.0 → 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.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/invalid_model/error_serializer.rb +2 -2
- data/lib/invalid_model/serializer.rb +10 -1
- metadata +2 -3
- data/lib/invalid_model.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 543bb4356cc6b9ecd6d08fc4904ce5d5df1e4221a31aaf3ecdbf0fc74d6146e9
|
4
|
+
data.tar.gz: 0463cc8a4ab67249f9c4ac4f6d55e88f6065293c9397f78deb6ebab5aeddd132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a336507a07aa87c5e8247fb82889dba941788b559867f59cfd45175cd1eb39d273890937601609e1a9358d6535be9ee2af7434911e541bd9576adf4359ec87
|
7
|
+
data.tar.gz: cb2112f61456fd5edd0daf70662fe9b6274210963fe69cf788daecfe5c6cd1104341772008f90d172f14f70b658fdd9d2cc35e90da572c70c17a948a3bd11f97
|
data/README.md
CHANGED
@@ -58,3 +58,13 @@ You can pass options to the serializer as 2nd argument. The following keys are s
|
|
58
58
|
* `code_format`: Override the default format. This string will be passed through a `format` method so you can use some placeholders like `type` and `attribute`.
|
59
59
|
* `status`: Set a different status, default is `400`
|
60
60
|
* `each_serializer`: Use your own serializer for error objects.
|
61
|
+
|
62
|
+
### Configuration
|
63
|
+
|
64
|
+
Additionally you can set `code_format` and `status` globally via:
|
65
|
+
```ruby
|
66
|
+
InvalidModel::Serializer.configure do |config|
|
67
|
+
config.code_format = 'validation_error/%{model}.%{attribute}.%{type}'
|
68
|
+
config.status = '422'
|
69
|
+
end
|
70
|
+
```
|
@@ -32,7 +32,7 @@ module InvalidModel
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def code_format
|
35
|
-
@options[:code_format] || InvalidModel.default_code_format
|
35
|
+
@options[:code_format] || InvalidModel::Serializer.default_code_format
|
36
36
|
end
|
37
37
|
|
38
38
|
def source
|
@@ -42,7 +42,7 @@ module InvalidModel
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def status
|
45
|
-
@options[:status] || InvalidModel.default_status
|
45
|
+
@options[:status] || InvalidModel::Serializer.default_status
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,7 +1,16 @@
|
|
1
|
-
|
1
|
+
# Bundler loading entrypoint
|
2
|
+
require 'active_support'
|
2
3
|
|
3
4
|
module InvalidModel
|
5
|
+
autoload :Error, 'invalid_model/error'
|
6
|
+
autoload :ErrorSerializer, 'invalid_model/error_serializer'
|
7
|
+
|
4
8
|
class Serializer
|
9
|
+
include ActiveSupport::Configurable
|
10
|
+
|
11
|
+
config_accessor(:default_code_format) { 'validation_error/%<type>s' }
|
12
|
+
config_accessor(:default_status) { '400' }
|
13
|
+
|
5
14
|
def initialize(resource, options = {})
|
6
15
|
@resource = resource
|
7
16
|
@options = options
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invalid_model-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,7 +123,6 @@ extra_rdoc_files: []
|
|
123
123
|
files:
|
124
124
|
- LICENSE
|
125
125
|
- README.md
|
126
|
-
- lib/invalid_model.rb
|
127
126
|
- lib/invalid_model/error.rb
|
128
127
|
- lib/invalid_model/error_serializer.rb
|
129
128
|
- lib/invalid_model/serializer.rb
|
data/lib/invalid_model.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module InvalidModel
|
4
|
-
autoload :Error, 'invalid_model/error'
|
5
|
-
autoload :ErrorSerializer, 'invalid_model/error_serializer'
|
6
|
-
|
7
|
-
include ActiveSupport::Configurable
|
8
|
-
|
9
|
-
config_accessor(:default_code_format) { 'validation_error/%<type>s' }
|
10
|
-
config_accessor(:default_status) { '400' }
|
11
|
-
end
|