Skip to content

Commit a7c0e4e

Browse files
committed
Make options hash not optional
1 parent 186ceff commit a7c0e4e

File tree

10 files changed

+84
-82
lines changed

10 files changed

+84
-82
lines changed

lib/jsonapi/active_relation/join_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def join_details_by_relationship(relationship)
7777
@join_details[segment]
7878
end
7979

80-
def self.get_join_arel_node(records, relationship, join_type, options = {})
80+
def self.get_join_arel_node(records, relationship, join_type, options)
8181
init_join_sources = records.arel.join_sources
8282
init_join_sources_length = init_join_sources.length
8383

lib/jsonapi/active_relation/join_manager_v10.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def join_details_by_relationship(relationship)
7272
@join_details[segment]
7373
end
7474

75-
def self.get_join_arel_node(records, relationship, join_type, options = {})
75+
def self.get_join_arel_node(records, relationship, join_type, options)
7676
init_join_sources = records.arel.join_sources
7777
init_join_sources_length = init_join_sources.length
7878

lib/jsonapi/active_relation_retrieval.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module JSONAPI
44
module ActiveRelationRetrieval
55
include ::JSONAPI::RelationRetrieval
66

7-
def find_related_ids(relationship, options = {})
7+
def find_related_ids(relationship, options)
88
self.class.find_related_fragments(self, relationship, options).keys.collect { |rid| rid.id }
99
end
1010

@@ -17,7 +17,7 @@ module ClassMethods
1717
# @option options [Hash] :include_directives The `include_directives`
1818
#
1919
# @return [Array<Resource>] the Resource instances matching the filters, sorting and pagination rules.
20-
def find(filters, options = {})
20+
def find(filters, options)
2121
sort_criteria = options.fetch(:sort_criteria) { [] }
2222

2323
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
@@ -41,7 +41,7 @@ def find(filters, options = {})
4141
# @option options [Hash] :context The context of the request, set in the controller
4242
#
4343
# @return [Integer] the count
44-
def count(filters, options = {})
44+
def count(filters, options)
4545
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
4646
filters: filters)
4747

@@ -57,7 +57,7 @@ def count(filters, options = {})
5757
#
5858
# @param key the primary key of the resource to find
5959
# @option options [Hash] :context The context of the request, set in the controller
60-
def find_by_key(key, options = {})
60+
def find_by_key(key, options)
6161
record = find_record_by_key(key, options)
6262
resource_for(record, options[:context])
6363
end
@@ -66,7 +66,7 @@ def find_by_key(key, options = {})
6666
#
6767
# @param keys [Array<key>] Array of primary keys to find resources for
6868
# @option options [Hash] :context The context of the request, set in the controller
69-
def find_by_keys(keys, options = {})
69+
def find_by_keys(keys, options)
7070
records = find_records_by_keys(keys, options)
7171
resources_for(records, options[:context])
7272
end
@@ -76,7 +76,7 @@ def find_by_keys(keys, options = {})
7676
#
7777
# @param keys [Array<key>] Array of primary keys to find resources for
7878
# @option options [Hash] :context The context of the request, set in the controller
79-
def find_to_populate_by_keys(keys, options = {})
79+
def find_to_populate_by_keys(keys, options)
8080
records = records_for_populate(options).where(_primary_key => keys)
8181
resources_for(records, options[:context])
8282
end
@@ -93,7 +93,7 @@ def find_to_populate_by_keys(keys, options = {})
9393
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field}]
9494
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
9595
# additional_field values
96-
def find_fragments(filters, options = {})
96+
def find_fragments(filters, options)
9797
include_directives = options.fetch(:include_directives, {})
9898
resource_klass = self
9999

@@ -259,7 +259,7 @@ def find_fragments(filters, options = {})
259259
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field, related: {relationship_name: [] }}}]
260260
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
261261
# additional_field values
262-
def find_related_fragments(source_fragment, relationship, options = {})
262+
def find_related_fragments(source_fragment, relationship, options)
263263
if relationship.polymorphic? # && relationship.foreign_key_on == :self
264264
source_resource_klasses = if relationship.foreign_key_on == :self
265265
relationship.polymorphic_types.collect do |polymorphic_type|
@@ -498,11 +498,11 @@ def find_related_fragments_from_inverse(source, source_relationship, options, co
498498
#
499499
# @return [Integer] the count
500500

501-
def count_related(source, relationship, options = {})
501+
def count_related(source, relationship, options)
502502
relationship.resource_klass.count_related_from_inverse(source, relationship, options)
503503
end
504504

505-
def count_related_from_inverse(source_resource, source_relationship, options = {})
505+
def count_related_from_inverse(source_resource, source_relationship, options)
506506
inverse_relationship = source_relationship._inverse_relationship
507507
return -1 if inverse_relationship.blank?
508508

@@ -542,7 +542,7 @@ def count_related_from_inverse(source_resource, source_relationship, options = {
542542
# @option options [Hash] :context The context of the request, set in the controller
543543
#
544544
# @return [ActiveRecord::Relation]
545-
def records_base(_options = {})
545+
def records_base(_options)
546546
_model_class.all
547547
end
548548

@@ -552,7 +552,7 @@ def records_base(_options = {})
552552
# @option options [Hash] :context The context of the request, set in the controller
553553
#
554554
# @return [ActiveRecord::Relation]
555-
def records(options = {})
555+
def records(options)
556556
records_base(options)
557557
end
558558

@@ -563,7 +563,7 @@ def records(options = {})
563563
# @option options [Hash] :context The context of the request, set in the controller
564564
#
565565
# @return [ActiveRecord::Relation]
566-
def records_for_populate(options = {})
566+
def records_for_populate(options)
567567
records_base(options)
568568
end
569569

@@ -572,7 +572,7 @@ def records_for_populate(options = {})
572572
# @option options [Hash] :context The context of the request, set in the controller
573573
#
574574
# @return [ActiveRecord::Relation]
575-
def records_for_source_to_related(options = {})
575+
def records_for_source_to_related(options)
576576
records_base(options)
577577
end
578578

@@ -637,13 +637,13 @@ def join_relationship(records:, relationship:, resource_type: nil, join_type: :i
637637

638638
# protected
639639

640-
def find_record_by_key(key, options = {})
640+
def find_record_by_key(key, options)
641641
record = apply_request_settings_to_records(records: records(options), primary_keys: key, options: options).first
642642
fail JSONAPI::Exceptions::RecordNotFound.new(key) if record.nil?
643643
record
644644
end
645645

646-
def find_records_by_keys(keys, options = {})
646+
def find_records_by_keys(keys, options)
647647
apply_request_settings_to_records(records: records(options), primary_keys: keys, options: options)
648648
end
649649

@@ -839,7 +839,7 @@ def quote(field)
839839
%{"#{field.to_s}"}
840840
end
841841

842-
def apply_filters(records, filters, options = {})
842+
def apply_filters(records, filters, options)
843843
if filters
844844
filters.each do |filter, value|
845845
records = apply_filter(records, filter, value, options)
@@ -865,7 +865,7 @@ def get_aliased_field(path_with_field, join_manager)
865865
concat_table_field(table_alias, field_segment.delegated_field_name)
866866
end
867867

868-
def apply_filter(records, filter, value, options = {})
868+
def apply_filter(records, filter, value, options)
869869
strategy = _allowed_filters.fetch(filter.to_sym, Hash.new)[:apply]
870870

871871
if strategy

lib/jsonapi/active_relation_retrieval_v09.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module JSONAPI
44
module ActiveRelationRetrievalV09
55
include ::JSONAPI::RelationRetrieval
66

7-
def find_related_ids(relationship, options = {})
7+
def find_related_ids(relationship, options)
88
self.class.find_related_fragments(self.fragment, relationship, options).keys.collect { |rid| rid.id }
99
end
1010

@@ -23,7 +23,7 @@ module ClassMethods
2323
# @option options [Hash] :include_directives The `include_directives`
2424
#
2525
# @return [Array<Resource>] the Resource instances matching the filters, sorting and pagination rules.
26-
def find(filters, options = {})
26+
def find(filters, options)
2727
context = options[:context]
2828

2929
records = filter_records(records(options), filters, options)
@@ -43,15 +43,15 @@ def find(filters, options = {})
4343
# @option options [Hash] :context The context of the request, set in the controller
4444
#
4545
# @return [Integer] the count
46-
def count(filters, options = {})
46+
def count(filters, options)
4747
count_records(filter_records(records(options), filters, options))
4848
end
4949

5050
# Returns the single Resource identified by `key`
5151
#
5252
# @param key the primary key of the resource to find
5353
# @option options [Hash] :context The context of the request, set in the controller
54-
def find_by_key(key, options = {})
54+
def find_by_key(key, options)
5555
context = options[:context]
5656
records = records(options)
5757

@@ -65,7 +65,7 @@ def find_by_key(key, options = {})
6565
#
6666
# @param keys [Array<key>] Array of primary keys to find resources for
6767
# @option options [Hash] :context The context of the request, set in the controller
68-
def find_by_keys(keys, options = {})
68+
def find_by_keys(keys, options)
6969
context = options[:context]
7070
records = records(options)
7171
records = apply_includes(records, options)
@@ -80,7 +80,7 @@ def find_by_keys(keys, options = {})
8080
#
8181
# @param keys [Array<key>] Array of primary keys to find resources for
8282
# @option options [Hash] :context The context of the request, set in the controller
83-
def find_to_populate_by_keys(keys, options = {})
83+
def find_to_populate_by_keys(keys, options)
8484
records = records_for_populate(options).where(_primary_key => keys)
8585
resources_for(records, options[:context])
8686
end
@@ -97,7 +97,7 @@ def find_to_populate_by_keys(keys, options = {})
9797
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field}]
9898
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
9999
# additional_field values
100-
def find_fragments(filters, options = {})
100+
def find_fragments(filters, options)
101101
context = options[:context]
102102

103103
sort_criteria = options.fetch(:sort_criteria) { [] }
@@ -208,7 +208,7 @@ def find_related_fragments_from_inverse(source, source_relationship, options, co
208208
#
209209
# @return [Integer] the count
210210

211-
def count_related(source, relationship, options = {})
211+
def count_related(source, relationship, options)
212212
opts = options.except(:paginator)
213213

214214
related_resource_records = source.public_send("records_for_#{relationship.name}",
@@ -229,7 +229,7 @@ def count_related(source, relationship, options = {})
229229
# @option options [Hash] :context The context of the request, set in the controller
230230
#
231231
# @return [ActiveRecord::Relation]
232-
def records_base(_options = {})
232+
def records_base(_options)
233233
_model_class.all
234234
end
235235

@@ -239,7 +239,7 @@ def records_base(_options = {})
239239
# @option options [Hash] :context The context of the request, set in the controller
240240
#
241241
# @return [ActiveRecord::Relation]
242-
def records(options = {})
242+
def records(options)
243243
records_base(options)
244244
end
245245

@@ -250,7 +250,7 @@ def records(options = {})
250250
# @option options [Hash] :context The context of the request, set in the controller
251251
#
252252
# @return [ActiveRecord::Relation]
253-
def records_for_populate(options = {})
253+
def records_for_populate(options)
254254
records_base(options)
255255
end
256256

@@ -259,7 +259,7 @@ def records_for_populate(options = {})
259259
# @option options [Hash] :context The context of the request, set in the controller
260260
#
261261
# @return [ActiveRecord::Relation]
262-
def records_for_source_to_related(options = {})
262+
def records_for_source_to_related(options)
263263
records_base(options)
264264
end
265265

@@ -481,7 +481,7 @@ def build_to_many(relationship, foreign_key, associated_records_method_name, rel
481481
end
482482
end
483483

484-
def resolve_relationship_names_to_relations(resource_klass, model_includes, options = {})
484+
def resolve_relationship_names_to_relations(resource_klass, model_includes, options)
485485
case model_includes
486486
when Array
487487
return model_includes.map do |value|
@@ -501,7 +501,7 @@ def resolve_relationship_names_to_relations(resource_klass, model_includes, opti
501501
end
502502
end
503503

504-
def apply_includes(records, options = {})
504+
def apply_includes(records, options)
505505
include_directives = options[:include_directives]
506506
if include_directives
507507
model_includes = resolve_relationship_names_to_relations(self, include_directives.model_includes, options)
@@ -615,7 +615,7 @@ def get_aliased_field(path_with_field, join_manager)
615615
concat_table_field(table_alias, field_segment.delegated_field_name)
616616
end
617617

618-
def apply_filter(records, filter, value, options = {})
618+
def apply_filter(records, filter, value, options)
619619
strategy = _allowed_filters.fetch(filter.to_sym, Hash.new)[:apply]
620620

621621
if strategy
@@ -629,7 +629,7 @@ def apply_filter(records, filter, value, options = {})
629629
records
630630
end
631631

632-
def apply_filters(records, filters, options = {})
632+
def apply_filters(records, filters, options)
633633
# required_includes = []
634634

635635
if filters
@@ -670,7 +670,7 @@ def construct_order_options(sort_params)
670670
end
671671
end
672672

673-
def sort_records(records, order_options, options = {})
673+
def sort_records(records, order_options, options)
674674
apply_sort(records, order_options, options)
675675
end
676676

@@ -679,7 +679,7 @@ def count_records(records)
679679
records.count(:all)
680680
end
681681

682-
def find_count(filters, options = {})
682+
def find_count(filters, options)
683683
count_records(filter_records(records(options), filters, options))
684684
end
685685

0 commit comments

Comments
 (0)