Class: JSONAPI::Configuration
- Inherits:
-
Object
- Object
- JSONAPI::Configuration
- Defined in:
- lib/jsonapi/configuration.rb
Instance Attribute Summary collapse
-
#allow_filter ⇒ Object
Returns the value of attribute allow_filter.
-
#allow_include ⇒ Object
Returns the value of attribute allow_include.
-
#allow_sort ⇒ Object
Returns the value of attribute allow_sort.
-
#allow_transactions ⇒ Object
Returns the value of attribute allow_transactions.
-
#always_include_to_many_linkage_data ⇒ Object
Returns the value of attribute always_include_to_many_linkage_data.
-
#always_include_to_one_linkage_data ⇒ Object
Returns the value of attribute always_include_to_one_linkage_data.
-
#cache_formatters ⇒ Object
Returns the value of attribute cache_formatters.
-
#default_page_size ⇒ Object
Returns the value of attribute default_page_size.
-
#default_paginator ⇒ Object
Returns the value of attribute default_paginator.
-
#default_processor_klass ⇒ Object
Returns the value of attribute default_processor_klass.
-
#exception_class_whitelist ⇒ Object
Returns the value of attribute exception_class_whitelist.
-
#json_key_format ⇒ Object
Returns the value of attribute json_key_format.
-
#maximum_page_size ⇒ Object
Returns the value of attribute maximum_page_size.
-
#raise_if_parameters_not_allowed ⇒ Object
Returns the value of attribute raise_if_parameters_not_allowed.
-
#resource_key_type ⇒ Object
Returns the value of attribute resource_key_type.
-
#route_format ⇒ Object
Returns the value of attribute route_format.
-
#top_level_links_include_pagination ⇒ Object
Returns the value of attribute top_level_links_include_pagination.
-
#top_level_meta_include_page_count ⇒ Object
Returns the value of attribute top_level_meta_include_page_count.
-
#top_level_meta_include_record_count ⇒ Object
Returns the value of attribute top_level_meta_include_record_count.
-
#top_level_meta_page_count_key ⇒ Object
Returns the value of attribute top_level_meta_page_count_key.
-
#top_level_meta_record_count_key ⇒ Object
Returns the value of attribute top_level_meta_record_count_key.
-
#use_relationship_reflection ⇒ Object
Returns the value of attribute use_relationship_reflection.
-
#use_text_errors ⇒ Object
Returns the value of attribute use_text_errors.
Instance Method Summary collapse
- #exception_class_whitelisted?(e) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #key_formatter ⇒ Object
- #route_formatter ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
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 92 93 94 95 96 97 |
# File 'lib/jsonapi/configuration.rb', line 31 def initialize #:underscored_key, :camelized_key, :dasherized_key, or custom self.json_key_format = :dasherized_key #:underscored_route, :camelized_route, :dasherized_route, or custom self.route_format = :dasherized_route #:integer, :uuid, :string, or custom (provide a proc) self.resource_key_type = :integer # optional request features self.allow_include = true self.allow_sort = true self.allow_filter = true self.raise_if_parameters_not_allowed = true # :none, :offset, :paged, or a custom paginator name self.default_paginator = :none # Output pagination links at top level self.top_level_links_include_pagination = true self.default_page_size = 10 self.maximum_page_size = 20 # Metadata # Output record count in top level meta for find operation self. = false self. = :record_count self. = false self. = :page_count self.use_text_errors = false # List of classes that should not be rescued by the operations processor. # For example, if you use Pundit for authorization, you might # raise a Pundit::NotAuthorizedError at some point during operations # processing. If you want to use Rails' `rescue_from` macro to # catch this error and render a 403 status code, you should add # the `Pundit::NotAuthorizedError` to the `exception_class_whitelist`. self.exception_class_whitelist = [] # Resource Linkage # Controls the serialization of resource linkage for non compound documents # NOTE: always_include_to_many_linkage_data is not currently implemented self.always_include_to_one_linkage_data = false self.always_include_to_many_linkage_data = false # The default Operation Processor to use if one is not defined specifically # for a Resource. self.default_processor_klass = JSONAPI::Processor # Allows transactions for creating and updating records # Set this to false if your backend does not support transactions (e.g. Mongodb) self.allow_transactions = true # Formatter Caching # Set to false to disable caching of string operations on keys and links. self.cache_formatters = true # Relationship reflection invokes the related resource when updates # are made to a has_many relationship. By default relationship_reflection # is turned off because it imposes a small performance penalty. self.use_relationship_reflection = false end |
Instance Attribute Details
#allow_filter ⇒ Object
Returns the value of attribute allow_filter.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def allow_filter @allow_filter end |
#allow_include ⇒ Object
Returns the value of attribute allow_include.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def allow_include @allow_include end |
#allow_sort ⇒ Object
Returns the value of attribute allow_sort.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def allow_sort @allow_sort end |
#allow_transactions ⇒ Object
Returns the value of attribute allow_transactions.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def allow_transactions @allow_transactions end |
#always_include_to_many_linkage_data ⇒ Object
Returns the value of attribute always_include_to_many_linkage_data.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def always_include_to_many_linkage_data @always_include_to_many_linkage_data end |
#always_include_to_one_linkage_data ⇒ Object
Returns the value of attribute always_include_to_one_linkage_data.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def always_include_to_one_linkage_data @always_include_to_one_linkage_data end |
#cache_formatters ⇒ Object
Returns the value of attribute cache_formatters.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def cache_formatters @cache_formatters end |
#default_page_size ⇒ Object
Returns the value of attribute default_page_size.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def default_page_size @default_page_size end |
#default_paginator ⇒ Object
Returns the value of attribute default_paginator.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def default_paginator @default_paginator end |
#default_processor_klass ⇒ Object
Returns the value of attribute default_processor_klass.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def default_processor_klass @default_processor_klass end |
#exception_class_whitelist ⇒ Object
Returns the value of attribute exception_class_whitelist.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def exception_class_whitelist @exception_class_whitelist end |
#json_key_format ⇒ Object
Returns the value of attribute json_key_format.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def json_key_format @json_key_format end |
#maximum_page_size ⇒ Object
Returns the value of attribute maximum_page_size.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def maximum_page_size @maximum_page_size end |
#raise_if_parameters_not_allowed ⇒ Object
Returns the value of attribute raise_if_parameters_not_allowed.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def raise_if_parameters_not_allowed @raise_if_parameters_not_allowed end |
#resource_key_type ⇒ Object
Returns the value of attribute resource_key_type.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def resource_key_type @resource_key_type end |
#route_format ⇒ Object
Returns the value of attribute route_format.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def route_format @route_format end |
#top_level_links_include_pagination ⇒ Object
Returns the value of attribute top_level_links_include_pagination.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def top_level_links_include_pagination @top_level_links_include_pagination end |
#top_level_meta_include_page_count ⇒ Object
Returns the value of attribute top_level_meta_include_page_count.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def @top_level_meta_include_page_count end |
#top_level_meta_include_record_count ⇒ Object
Returns the value of attribute top_level_meta_include_record_count.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def @top_level_meta_include_record_count end |
#top_level_meta_page_count_key ⇒ Object
Returns the value of attribute top_level_meta_page_count_key.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def @top_level_meta_page_count_key end |
#top_level_meta_record_count_key ⇒ Object
Returns the value of attribute top_level_meta_record_count_key.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def @top_level_meta_record_count_key end |
#use_relationship_reflection ⇒ Object
Returns the value of attribute use_relationship_reflection.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def use_relationship_reflection @use_relationship_reflection end |
#use_text_errors ⇒ Object
Returns the value of attribute use_text_errors.
7 8 9 |
# File 'lib/jsonapi/configuration.rb', line 7 def use_text_errors @use_text_errors end |
Instance Method Details
#exception_class_whitelisted?(e) ⇒ Boolean
158 159 160 |
# File 'lib/jsonapi/configuration.rb', line 158 def exception_class_whitelisted?(e) @exception_class_whitelist.flatten.any? { |k| e.class.ancestors.include?(k) } end |
#key_formatter ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/jsonapi/configuration.rb', line 124 def key_formatter if self.cache_formatters formatter = @key_formatter_tlv.value return formatter if formatter end formatter = JSONAPI::Formatter.formatter_for(self.json_key_format) if self.cache_formatters formatter = @key_formatter_tlv.value = formatter.cached end return formatter end |
#route_formatter ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/jsonapi/configuration.rb', line 143 def route_formatter if self.cache_formatters formatter = @route_formatter_tlv.value return formatter if formatter end formatter = JSONAPI::Formatter.formatter_for(self.route_format) if self.cache_formatters formatter = @route_formatter_tlv.value = formatter.cached end return formatter end |