|
4 | 4 | module JSONAPI |
5 | 5 | module Rails |
6 | 6 | class Configuration < ActiveSupport::InheritableOptions; end |
7 | | - DEFAULT_JSONAPI_CLASS = Hash.new do |h, k| |
8 | | - names = k.to_s.split('::') |
9 | | - klass = names.pop |
10 | | - h[k] = [*names, "Serializable#{klass}"].join('::').safe_constantize |
11 | | - end.freeze |
12 | | - |
13 | | - DEFAULT_JSONAPI_ERRORS_CLASS = DEFAULT_JSONAPI_CLASS.dup.merge!( |
14 | | - 'ActiveModel::Errors'.to_sym => |
| 7 | + |
| 8 | + # @private |
| 9 | + module Configurable |
| 10 | + DEFAULT_JSONAPI_CLASS = Hash.new do |h, k| |
| 11 | + names = k.to_s.split('::') |
| 12 | + klass = names.pop |
| 13 | + h[k] = [*names, "Serializable#{klass}"].join('::').safe_constantize |
| 14 | + end.freeze |
| 15 | + |
| 16 | + DEFAULT_JSONAPI_ERRORS_CLASS = DEFAULT_JSONAPI_CLASS.dup.merge!( |
| 17 | + 'ActiveModel::Errors'.to_sym => |
15 | 18 | JSONAPI::Rails::SerializableActiveModelErrors, |
16 | | - 'Hash'.to_sym => JSONAPI::Rails::SerializableErrorHash |
17 | | - ).freeze |
| 19 | + 'Hash'.to_sym => JSONAPI::Rails::SerializableErrorHash |
| 20 | + ).freeze |
18 | 21 |
|
19 | | - DEFAULT_JSONAPI_OBJECT = { |
20 | | - version: '1.0' |
21 | | - }.freeze |
| 22 | + DEFAULT_JSONAPI_OBJECT = { |
| 23 | + version: '1.0' |
| 24 | + }.freeze |
22 | 25 |
|
23 | | - DEFAULT_JSONAPI_EXPOSE = lambda { |
24 | | - { url_helpers: ::Rails.application.routes.url_helpers } |
25 | | - }.freeze |
| 26 | + DEFAULT_JSONAPI_EXPOSE = lambda { |
| 27 | + { url_helpers: ::Rails.application.routes.url_helpers } |
| 28 | + } |
26 | 29 |
|
27 | | - DEFAULT_JSONAPI_PAGINATION = ->(_) { nil } |
| 30 | + DEFAULT_JSONAPI_FIELDS = ->() { nil } |
28 | 31 |
|
29 | | - DEFAULT_CONFIG = { |
30 | | - jsonapi_class: DEFAULT_JSONAPI_CLASS, |
31 | | - jsonapi_errors_class: DEFAULT_JSONAPI_ERRORS_CLASS, |
32 | | - jsonapi_object: DEFAULT_JSONAPI_OBJECT, |
33 | | - jsonapi_expose: DEFAULT_JSONAPI_EXPOSE, |
34 | | - jsonapi_pagination: DEFAULT_JSONAPI_PAGINATION |
35 | | - }.freeze |
| 32 | + DEFAULT_JSONAPI_INCLUDE = ->() { nil } |
36 | 33 |
|
37 | | - def self.configure |
38 | | - yield config |
39 | | - end |
| 34 | + DEFAULT_JSONAPI_LINKS = ->() { {} } |
| 35 | + |
| 36 | + DEFAULT_JSONAPI_PAGINATION = ->(_) { {} } |
| 37 | + |
| 38 | + DEFAULT_CONFIG = { |
| 39 | + jsonapi_class: DEFAULT_JSONAPI_CLASS, |
| 40 | + jsonapi_errors_class: DEFAULT_JSONAPI_ERRORS_CLASS, |
| 41 | + jsonapi_expose: DEFAULT_JSONAPI_EXPOSE, |
| 42 | + jsonapi_fields: DEFAULT_JSONAPI_FIELDS, |
| 43 | + jsonapi_include: DEFAULT_JSONAPI_INCLUDE, |
| 44 | + jsonapi_links: DEFAULT_JSONAPI_LINKS, |
| 45 | + jsonapi_object: DEFAULT_JSONAPI_OBJECT, |
| 46 | + jsonapi_pagination: DEFAULT_JSONAPI_PAGINATION |
| 47 | + }.freeze |
| 48 | + |
| 49 | + def configure |
| 50 | + yield config |
| 51 | + end |
40 | 52 |
|
41 | | - def self.config |
42 | | - @config ||= JSONAPI::Rails::Configuration.new(DEFAULT_CONFIG) |
| 53 | + def config |
| 54 | + @config ||= JSONAPI::Rails::Configuration.new(DEFAULT_CONFIG) |
| 55 | + end |
43 | 56 | end |
44 | 57 | end |
45 | 58 | end |
0 commit comments