@@ -534,23 +534,22 @@ Callbacks can also be defined for `JSONAPI::OperationsProcessor` events:
534534- ` :remove_has_many_association_operation ` : A ` remove_has_many_association_operation ` .
535535- ` :remove_has_one_association_operation ` : A ` remove_has_one_association_operation ` .
536536
537- The operation callbacks have access to two meta data hashes, ` @operations_meta ` and ` @operation_meta ` , the full list of
538- ` @operations ` , each individual ` @operation ` and the ` @result ` variables.
537+ The operation callbacks have access to two meta data hashes, ` @operations_meta ` and ` @operation_meta ` , two links hashes,
538+ ` @operations_links ` and ` @operation_links ` , the full list of ` @operations ` , each individual ` @operation ` and the
539+ ` @result ` variables.
539540
540541##### Custom ` OperationsProcessor ` Example to Return total_count in Meta
541542
543+ Note: this can also be accomplished with the ` top_level_meta_include_record_count ` option, and in most cases that will
544+ be the better option.
545+
542546To return the total record count of a find operation in the meta data of a find operation you can create a custom
543547OperationsProcessor. For example:
544548
545549``` ruby
546550class CountingActiveRecordOperationsProcessor < ActiveRecordOperationsProcessor
547551 after_find_operation do
548- count = @operation .resource_klass.find_count(@operation .resource_klass.verify_filters(@operation .filters, @context ),
549- context: @context ,
550- include_directives: @operation .include_directives,
551- sort_criteria: @operation .sort_criteria)
552-
553- @operation_meta [:total_records ] = count
552+ @operation_meta [:total_records ] = @operation .record_count
554553 end
555554end
556555```
@@ -1179,6 +1178,42 @@ end
11791178
11801179You would specify this in ` JSONAPI.configure ` as ` :upper_camelized ` .
11811180
1181+ ## Configuration
1182+
1183+ JR has a few configuration options. Some have already been mentioned above. To set configuration options create an
1184+ initializer and add the options you wish to set. All options have defaults, so you only need to set the options that
1185+ are different. The default options are shown below.
1186+
1187+ ``` ruby
1188+ JSONAPI .configure do |config |
1189+ # :underscored_key, :camelized_key, :dasherized_key, or custom
1190+ config.json_key_format = :dasherized_key
1191+
1192+ # :underscored_route, :camelized_route, :dasherized_route, or custom
1193+ config.route_format = :dasherized_route
1194+
1195+ # :basic, :active_record, or custom
1196+ config.operations_processor = :active_record
1197+
1198+ config.allowed_request_params = [:include , :fields , :format , :controller , :action , :sort , :page ]
1199+
1200+ # :none, :offset, :paged, or a custom paginator name
1201+ config.default_paginator = :none
1202+
1203+ # Output pagination links at top level
1204+ config.top_level_links_include_pagination = true
1205+
1206+ config.default_page_size = 10
1207+ config.maximum_page_size = 20
1208+
1209+ # Output the record count in top level meta data for find operations
1210+ config.top_level_meta_include_record_count = false
1211+ config.top_level_meta_record_count_key = :record_count
1212+
1213+ config.use_text_errors = false
1214+ end
1215+ ```
1216+
11821217## Contributing
11831218
118412191 . Fork it ( http://github.com/cerebris/jsonapi-resources/fork )
0 commit comments