invalid_model-serializer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df1242852f66172d00295ccb760575223afa3eb03dc8603862d39c9ed3638f9b
4
- data.tar.gz: 2ee8cb553eca6bcbc2c17e81cf35410d3e5f2a58de5a5deffa2f133701464e29
3
+ metadata.gz: 543bb4356cc6b9ecd6d08fc4904ce5d5df1e4221a31aaf3ecdbf0fc74d6146e9
4
+ data.tar.gz: 0463cc8a4ab67249f9c4ac4f6d55e88f6065293c9397f78deb6ebab5aeddd132
5
5
  SHA512:
6
- metadata.gz: 45263b982a706e315c9557a594fff5c9a23c186dafacac70fe4ccd4df8dc8535e23baea9e0d147eca3f08c1468074326d4c13ee71c8d2b888ff2a47818ee4c6b
7
- data.tar.gz: 529e8846f8f95c50d327c08c847e2683d237f79302ba603d4dacb5987ca0516897f00e09df071a345d7ac4a9dff87a7d1a35097ad2bb8b79e09ecfe5633dc6b8
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
- require 'invalid_model'
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.0
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-17 00:00:00.000000000 Z
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