Skip to content

Commit 769b07a

Browse files
committed
Make options hash not optional
1 parent ef0551d commit 769b07a

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
@@ -2,7 +2,7 @@
22

33
module JSONAPI
44
module ActiveRelationRetrieval
5-
def find_related_ids(relationship, options = {})
5+
def find_related_ids(relationship, options)
66
self.class.find_related_fragments(self, relationship, options).keys.collect { |rid| rid.id }
77
end
88

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

2121
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
@@ -39,7 +39,7 @@ def find(filters, options = {})
3939
# @option options [Hash] :context The context of the request, set in the controller
4040
#
4141
# @return [Integer] the count
42-
def count(filters, options = {})
42+
def count(filters, options)
4343
join_manager = ActiveRelation::JoinManager.new(resource_klass: self,
4444
filters: filters)
4545

@@ -55,7 +55,7 @@ def count(filters, options = {})
5555
#
5656
# @param key the primary key of the resource to find
5757
# @option options [Hash] :context The context of the request, set in the controller
58-
def find_by_key(key, options = {})
58+
def find_by_key(key, options)
5959
record = find_record_by_key(key, options)
6060
resource_for(record, options[:context])
6161
end
@@ -64,7 +64,7 @@ def find_by_key(key, options = {})
6464
#
6565
# @param keys [Array<key>] Array of primary keys to find resources for
6666
# @option options [Hash] :context The context of the request, set in the controller
67-
def find_by_keys(keys, options = {})
67+
def find_by_keys(keys, options)
6868
records = find_records_by_keys(keys, options)
6969
resources_for(records, options[:context])
7070
end
@@ -74,7 +74,7 @@ def find_by_keys(keys, options = {})
7474
#
7575
# @param keys [Array<key>] Array of primary keys to find resources for
7676
# @option options [Hash] :context The context of the request, set in the controller
77-
def find_to_populate_by_keys(keys, options = {})
77+
def find_to_populate_by_keys(keys, options)
7878
records = records_for_populate(options).where(_primary_key => keys)
7979
resources_for(records, options[:context])
8080
end
@@ -91,7 +91,7 @@ def find_to_populate_by_keys(keys, options = {})
9191
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field}]
9292
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
9393
# additional_field values
94-
def find_fragments(filters, options = {})
94+
def find_fragments(filters, options)
9595
include_directives = options.fetch(:include_directives, {})
9696
resource_klass = self
9797

@@ -257,7 +257,7 @@ def find_fragments(filters, options = {})
257257
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field, related: {relationship_name: [] }}}]
258258
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
259259
# additional_field values
260-
def find_related_fragments(source_fragment, relationship, options = {})
260+
def find_related_fragments(source_fragment, relationship, options)
261261
if relationship.polymorphic? # && relationship.foreign_key_on == :self
262262
source_resource_klasses = if relationship.foreign_key_on == :self
263263
relationship.class.polymorphic_types(relationship.name).collect do |polymorphic_type|
@@ -489,11 +489,11 @@ def find_related_fragments_from_inverse(source, source_relationship, options, co
489489
#
490490
# @return [Integer] the count
491491

492-
def count_related(source, relationship, options = {})
492+
def count_related(source, relationship, options)
493493
relationship.resource_klass.count_related_from_inverse(source, relationship, options)
494494
end
495495

496-
def count_related_from_inverse(source_resource, source_relationship, options = {})
496+
def count_related_from_inverse(source_resource, source_relationship, options)
497497
relationship = source_relationship.resource_klass._relationship(source_relationship.inverse_relationship)
498498

499499
related_klass = relationship.resource_klass
@@ -532,7 +532,7 @@ def count_related_from_inverse(source_resource, source_relationship, options = {
532532
# @option options [Hash] :context The context of the request, set in the controller
533533
#
534534
# @return [ActiveRecord::Relation]
535-
def records_base(_options = {})
535+
def records_base(_options)
536536
_model_class.all
537537
end
538538

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

@@ -553,7 +553,7 @@ def records(options = {})
553553
# @option options [Hash] :context The context of the request, set in the controller
554554
#
555555
# @return [ActiveRecord::Relation]
556-
def records_for_populate(options = {})
556+
def records_for_populate(options)
557557
records_base(options)
558558
end
559559

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

@@ -627,13 +627,13 @@ def join_relationship(records:, relationship:, resource_type: nil, join_type: :i
627627

628628
# protected
629629

630-
def find_record_by_key(key, options = {})
630+
def find_record_by_key(key, options)
631631
record = apply_request_settings_to_records(records: records(options), primary_keys: key, options: options).first
632632
fail JSONAPI::Exceptions::RecordNotFound.new(key) if record.nil?
633633
record
634634
end
635635

636-
def find_records_by_keys(keys, options = {})
636+
def find_records_by_keys(keys, options)
637637
apply_request_settings_to_records(records: records(options), primary_keys: keys, options: options)
638638
end
639639

@@ -829,7 +829,7 @@ def quote(field)
829829
%{"#{field.to_s}"}
830830
end
831831

832-
def apply_filters(records, filters, options = {})
832+
def apply_filters(records, filters, options)
833833
if filters
834834
filters.each do |filter, value|
835835
records = apply_filter(records, filter, value, options)
@@ -855,7 +855,7 @@ def get_aliased_field(path_with_field, join_manager)
855855
concat_table_field(table_alias, field_segment.delegated_field_name)
856856
end
857857

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

861861
if strategy

lib/jsonapi/active_relation_retrieval_v09.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module JSONAPI
44
module ActiveRelationRetrievalV09
5-
def find_related_ids(relationship, options = {})
5+
def find_related_ids(relationship, options)
66
self.class.find_related_fragments(self.fragment, relationship, options).keys.collect { |rid| rid.id }
77
end
88

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

2727
records = filter_records(records(options), filters, options)
@@ -41,15 +41,15 @@ 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
count_records(filter_records(records(options), filters, options))
4646
end
4747

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

@@ -63,7 +63,7 @@ def find_by_key(key, options = {})
6363
#
6464
# @param keys [Array<key>] Array of primary keys to find resources for
6565
# @option options [Hash] :context The context of the request, set in the controller
66-
def find_by_keys(keys, options = {})
66+
def find_by_keys(keys, options)
6767
context = options[:context]
6868
records = records(options)
6969
records = apply_includes(records, options)
@@ -78,7 +78,7 @@ def find_by_keys(keys, options = {})
7878
#
7979
# @param keys [Array<key>] Array of primary keys to find resources for
8080
# @option options [Hash] :context The context of the request, set in the controller
81-
def find_to_populate_by_keys(keys, options = {})
81+
def find_to_populate_by_keys(keys, options)
8282
records = records_for_populate(options).where(_primary_key => keys)
8383
resources_for(records, options[:context])
8484
end
@@ -95,7 +95,7 @@ def find_to_populate_by_keys(keys, options = {})
9595
# @return [Hash{ResourceIdentity => {identity: => ResourceIdentity, cache: cache_field}]
9696
# the ResourceInstances matching the filters, sorting, and pagination rules along with any request
9797
# additional_field values
98-
def find_fragments(filters, options = {})
98+
def find_fragments(filters, options)
9999
context = options[:context]
100100

101101
sort_criteria = options.fetch(:sort_criteria) { [] }
@@ -201,7 +201,7 @@ def find_related_fragments_from_inverse(source, source_relationship, options, co
201201
#
202202
# @return [Integer] the count
203203

204-
def count_related(source, relationship, options = {})
204+
def count_related(source, relationship, options)
205205
opts = options.except(:paginator)
206206

207207
related_resource_records = source.public_send("records_for_#{relationship.name}",
@@ -222,7 +222,7 @@ def count_related(source, relationship, options = {})
222222
# @option options [Hash] :context The context of the request, set in the controller
223223
#
224224
# @return [ActiveRecord::Relation]
225-
def records_base(_options = {})
225+
def records_base(_options)
226226
_model_class.all
227227
end
228228

@@ -232,7 +232,7 @@ def records_base(_options = {})
232232
# @option options [Hash] :context The context of the request, set in the controller
233233
#
234234
# @return [ActiveRecord::Relation]
235-
def records(options = {})
235+
def records(options)
236236
records_base(options)
237237
end
238238

@@ -243,7 +243,7 @@ def records(options = {})
243243
# @option options [Hash] :context The context of the request, set in the controller
244244
#
245245
# @return [ActiveRecord::Relation]
246-
def records_for_populate(options = {})
246+
def records_for_populate(options)
247247
records_base(options)
248248
end
249249

@@ -252,7 +252,7 @@ def records_for_populate(options = {})
252252
# @option options [Hash] :context The context of the request, set in the controller
253253
#
254254
# @return [ActiveRecord::Relation]
255-
def records_for_source_to_related(options = {})
255+
def records_for_source_to_related(options)
256256
records_base(options)
257257
end
258258

@@ -472,7 +472,7 @@ def build_to_many(relationship, foreign_key, associated_records_method_name, rel
472472
end
473473
end
474474

475-
def resolve_relationship_names_to_relations(resource_klass, model_includes, options = {})
475+
def resolve_relationship_names_to_relations(resource_klass, model_includes, options)
476476
case model_includes
477477
when Array
478478
return model_includes.map do |value|
@@ -492,7 +492,7 @@ def resolve_relationship_names_to_relations(resource_klass, model_includes, opti
492492
end
493493
end
494494

495-
def apply_includes(records, options = {})
495+
def apply_includes(records, options)
496496
include_directives = options[:include_directives]
497497
if include_directives
498498
model_includes = resolve_relationship_names_to_relations(self, include_directives.model_includes, options)
@@ -606,7 +606,7 @@ def get_aliased_field(path_with_field, join_manager)
606606
concat_table_field(table_alias, field_segment.delegated_field_name)
607607
end
608608

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

612612
if strategy
@@ -620,7 +620,7 @@ def apply_filter(records, filter, value, options = {})
620620
records
621621
end
622622

623-
def apply_filters(records, filters, options = {})
623+
def apply_filters(records, filters, options)
624624
# required_includes = []
625625

626626
if filters
@@ -661,7 +661,7 @@ def construct_order_options(sort_params)
661661
end
662662
end
663663

664-
def sort_records(records, order_options, options = {})
664+
def sort_records(records, order_options, options)
665665
apply_sort(records, order_options, options)
666666
end
667667

@@ -670,7 +670,7 @@ def count_records(records)
670670
records.count(:all)
671671
end
672672

673-
def find_count(filters, options = {})
673+
def find_count(filters, options)
674674
count_records(filter_records(records(options), filters, options))
675675
end
676676

0 commit comments

Comments
 (0)