Skip to content

Commit 557f348

Browse files
committed
Make options hash not optional
1 parent bb00bbd commit 557f348

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, options = {})
80+
def self.get_join_arel_node(records, 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, options = {})
75+
def self.get_join_arel_node(records, 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
relationship = source_relationship.resource_klass._relationship(source_relationship.inverse_relationship)
507507

508508
related_klass = relationship.resource_klass
@@ -541,7 +541,7 @@ def count_related_from_inverse(source_resource, source_relationship, options = {
541541
# @option options [Hash] :context The context of the request, set in the controller
542542
#
543543
# @return [ActiveRecord::Relation]
544-
def records_base(_options = {})
544+
def records_base(_options)
545545
_model_class.all
546546
end
547547

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

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

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

@@ -636,13 +636,13 @@ def join_relationship(records:, relationship:, resource_type: nil, join_type: :i
636636

637637
# protected
638638

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

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

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

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

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

870870
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

@@ -479,7 +479,7 @@ def build_to_many(relationship, foreign_key, associated_records_method_name, rel
479479
end
480480
end
481481

482-
def resolve_relationship_names_to_relations(resource_klass, model_includes, options = {})
482+
def resolve_relationship_names_to_relations(resource_klass, model_includes, options)
483483
case model_includes
484484
when Array
485485
return model_includes.map do |value|
@@ -499,7 +499,7 @@ def resolve_relationship_names_to_relations(resource_klass, model_includes, opti
499499
end
500500
end
501501

502-
def apply_includes(records, options = {})
502+
def apply_includes(records, options)
503503
include_directives = options[:include_directives]
504504
if include_directives
505505
model_includes = resolve_relationship_names_to_relations(self, include_directives.model_includes, options)
@@ -613,7 +613,7 @@ def get_aliased_field(path_with_field, join_manager)
613613
concat_table_field(table_alias, field_segment.delegated_field_name)
614614
end
615615

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

619619
if strategy
@@ -627,7 +627,7 @@ def apply_filter(records, filter, value, options = {})
627627
records
628628
end
629629

630-
def apply_filters(records, filters, options = {})
630+
def apply_filters(records, filters, options)
631631
# required_includes = []
632632

633633
if filters
@@ -668,7 +668,7 @@ def construct_order_options(sort_params)
668668
end
669669
end
670670

671-
def sort_records(records, order_options, options = {})
671+
def sort_records(records, order_options, options)
672672
apply_sort(records, order_options, options)
673673
end
674674

@@ -677,7 +677,7 @@ def count_records(records)
677677
records.count(:all)
678678
end
679679

680-
def find_count(filters, options = {})
680+
def find_count(filters, options)
681681
count_records(filter_records(records(options), filters, options))
682682
end
683683

0 commit comments

Comments
 (0)