-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathinitializer.rb
91 lines (91 loc) · 2.98 KB
/
initializer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
JSONAPI::Rails.configure do |config|
# # Set a default serializable class mapping.
# config.jsonapi_class = Hash.new { |h, k|
# names = k.to_s.split('::')
# klass = names.pop
# h[k] = [*names, "Serializable#{klass}"].join('::').safe_constantize
# }
#
# # Set a default serializable class mapping for errors.
# config.jsonapi_errors_class = Hash.new { |h, k|
# names = k.to_s.split('::')
# klass = names.pop
# h[k] = [*names, "Serializable#{klass}"].join('::').safe_constantize
# }.tap { |h|
# h[:'ActiveModel::Errors'] = JSONAPI::Rails::SerializableActiveModelErrors
# h[:Hash] = JSONAPI::Rails::SerializableErrorHash
# }
#
# # Set a default JSON API object.
# config.jsonapi_object = {
# version: '1.0'
# }
#
# # Set default cache.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_cache = ->() { nil }
#
# # Uncomment the following to enable fragment caching. Make sure you
# # invalidate cache keys accordingly.
# config.jsonapi_cache = lambda {
# Rails.cache
# }
#
# # Set default exposures.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_expose = lambda {
# { url_helpers: ::Rails.application.routes.url_helpers }
# }
#
# # Set default fields.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_fields = ->() { nil }
#
# # Uncomment the following to have it default to the `fields` query
# # parameter.
# config.jsonapi_fields = lambda {
# fields_param = params.to_unsafe_hash.fetch(:fields, {})
# Hash[fields_param.map { |k, v| [k.to_sym, v.split(',').map!(&:to_sym)] }]
# }
#
# # Set default include.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_include = ->() { nil }
#
# # Uncomment the following to have it default to the `include` query
# # parameter.
# config.jsonapi_include = lambda {
# params[:include]
# }
#
# # Set default links.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_links = ->() { {} }
#
# # Set default meta.
# # A lambda/proc that will be eval'd in the controller context.
# config.jsonapi_meta = ->() { nil }
#
# # Set a default pagination scheme.
# config.jsonapi_pagination = ->(_) { {} }
#
# # Set the default action when the payload cannot be deserialized
# config.jsonapi_payload_malformed = -> {
# render jsonapi_errors: {
# title: 'Non-compliant Request Body',
# detail: 'The request was not formatted in compliance with the application/vnd.api+json spec',
# links: {
# about: 'http://jsonapi.org/format/'
# }
# }, status: :bad_request
# }
#
# # Uncomment to take no action when the payload cannot be deserialized
# config.jsonapi_payload_malformed = nil
#
# # Set a logger.
# config.logger = Logger.new(STDOUT)
#
# # Uncomment the following to disable logging.
# config.logger = Logger.new('/dev/null')
end