jsonapi-resources 0.10.0.beta8 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8058151c97ec20cfa1d8d1606c19a0c24094fb7f70e27970772d5e0df5cc96b
4
- data.tar.gz: 24604b487e967e5e24260e5d30d8a3f5891c6bf3fd1b1d8554a2f4eced9f503f
3
+ metadata.gz: 12f47ee89d33c3dc5b366b6538fe8af7719516ae5dfedab08f9d70ae28f378c9
4
+ data.tar.gz: 67c77d1af31817ed6126f43481fd3cc122dc9387c2187c0d09fd29503a402e58
5
5
  SHA512:
6
- metadata.gz: 9f486e212c1a44a440d4dad9b94c822a72e4080eca619e3838e8f4d1237223c882abf7f19c35cfa98af90a30d5f5799f79272f4393b0d8453134f7942fb14333
7
- data.tar.gz: 299ed1970270e8d69deea9a5a4fe6f67909a915c0c76f1d0608b3ce0ff3d82dbe1676a74082677e65ff9f0cbfa4ba97dc4be88ef46ffe52bac8e42b36810fedf
6
+ metadata.gz: d7c39545ce4f74f8068c8841796806ba5c757bac2bd830fd0bacb1facd21810bfbcb5e40b2ec501cf9558e1069ff9e3dfaf43b7a942b17200dcdf028a0e98432
7
+ data.tar.gz: 3ef5723ed2f96673d14372a2c11f28224d381fabe9a8c8b3b9373f8d6868a930de49349cdccff9203dab6b417241043635b84a9470bf41c4fb96096991b61e98
@@ -7,7 +7,13 @@ require 'jsonapi/resource'
7
7
  require 'jsonapi/cached_response_fragment'
8
8
  require 'jsonapi/response_document'
9
9
  require 'jsonapi/acts_as_resource_controller'
10
- require 'jsonapi/resource_controller'
10
+ if Rails::VERSION::MAJOR >= 6
11
+ ActiveSupport.on_load(:action_controller_base) do
12
+ require 'jsonapi/resource_controller'
13
+ end
14
+ else
15
+ require 'jsonapi/resource_controller'
16
+ end
11
17
  require 'jsonapi/resource_controller_metal'
12
18
  require 'jsonapi/resources/version'
13
19
  require 'jsonapi/configuration'
@@ -8,7 +8,7 @@ module JSONAPI
8
8
  # example Post.joins(:comments).joins_left(comments: :author) will join the comments table twice,
9
9
  # once inner and once left in 5.2, but only as inner in earlier versions.
10
10
  def joins_left(*columns)
11
- if Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2
11
+ if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
12
12
  left_joins(columns)
13
13
  else
14
14
  join_dependency = ActiveRecord::Associations::JoinDependency.new(self, columns, [])
@@ -153,6 +153,11 @@ module JSONAPI
153
153
  pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, model_field[:name])} AS #{resource_table_alias}_#{model_field[:name]}")
154
154
  end
155
155
 
156
+ sort_fields = options.dig(:_relation_helper_options, :sort_fields)
157
+ sort_fields.try(:each) do |field|
158
+ pluck_fields << Arel.sql(field)
159
+ end
160
+
156
161
  fragments = {}
157
162
  rows = records.pluck(*pluck_fields)
158
163
  rows.each do |row|
@@ -390,7 +395,7 @@ module JSONAPI
390
395
  sort_criteria: sort_criteria,
391
396
  filters: filters)
392
397
 
393
- paginator = options[:paginator] if source_rids.count == 1
398
+ paginator = options[:paginator]
394
399
 
395
400
  records = apply_request_settings_to_records(records: records_for_source_to_related(options),
396
401
  resource_klass: resource_klass,
@@ -445,6 +450,11 @@ module JSONAPI
445
450
  pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, model_field[:name])} AS #{resource_table_alias}_#{model_field[:name]}")
446
451
  end
447
452
 
453
+ sort_fields = options.dig(:_relation_helper_options, :sort_fields)
454
+ sort_fields.try(:each) do |field|
455
+ pluck_fields << Arel.sql(field)
456
+ end
457
+
448
458
  fragments = {}
449
459
  rows = records.distinct.pluck(*pluck_fields)
450
460
  rows.each do |row|
@@ -515,7 +525,7 @@ module JSONAPI
515
525
  relationships: linkage_relationships,
516
526
  filters: filters)
517
527
 
518
- paginator = options[:paginator] if source_rids.count == 1
528
+ paginator = options[:paginator]
519
529
 
520
530
  # Note: We will sort by the source table. Without using unions we can't sort on a polymorphic relationship
521
531
  # in any manner that makes sense
@@ -680,24 +690,23 @@ module JSONAPI
680
690
  paginator: nil,
681
691
  options: {})
682
692
 
683
- opts = options.dup
684
- records = resource_klass.apply_joins(records, join_manager, opts)
693
+ options[:_relation_helper_options] = { join_manager: join_manager, sort_fields: [] }
694
+
695
+ records = resource_klass.apply_joins(records, join_manager, options)
685
696
 
686
697
  if primary_keys
687
698
  records = records.where(_primary_key => primary_keys)
688
699
  end
689
700
 
690
- opts[:join_manager] = join_manager
691
-
692
701
  unless filters.empty?
693
- records = resource_klass.filter_records(records, filters, opts)
702
+ records = resource_klass.filter_records(records, filters, options)
694
703
  end
695
704
 
696
705
  if sort_primary
697
706
  records = records.order(_primary_key => :asc)
698
707
  else
699
708
  order_options = resource_klass.construct_order_options(sort_criteria)
700
- records = resource_klass.sort_records(records, order_options, opts)
709
+ records = resource_klass.sort_records(records, order_options, options)
701
710
  end
702
711
 
703
712
  if paginator
@@ -731,12 +740,16 @@ module JSONAPI
731
740
 
732
741
  strategy = _allowed_sort.fetch(field.to_sym, {})[:apply]
733
742
 
743
+ options[:_relation_helper_options] ||= {}
744
+ options[:_relation_helper_options][:sort_fields] ||= []
745
+
734
746
  if strategy
735
747
  records = call_method_or_proc(strategy, records, direction, context)
736
748
  else
737
- join_manager = options[:join_manager]
738
-
739
- records = records.order(Arel.sql("#{get_aliased_field(field, join_manager)} #{direction}"))
749
+ join_manager = options.dig(:_relation_helper_options, :join_manager)
750
+ sort_field = join_manager ? get_aliased_field(field, join_manager) : field
751
+ options[:_relation_helper_options][:sort_fields].push("#{sort_field}")
752
+ records = records.order(Arel.sql("#{sort_field} #{direction}"))
740
753
  end
741
754
  records
742
755
  end
@@ -825,8 +838,9 @@ module JSONAPI
825
838
  if strategy
826
839
  records = call_method_or_proc(strategy, records, value, options)
827
840
  else
828
- join_manager = options[:join_manager]
829
- records = records.where(Arel.sql(get_aliased_field(filter, join_manager)) => value)
841
+ join_manager = options.dig(:_relation_helper_options, :join_manager)
842
+ field = join_manager ? get_aliased_field(filter, join_manager) : filter
843
+ records = records.where(Arel.sql(field) => value)
830
844
  end
831
845
 
832
846
  records
@@ -152,7 +152,7 @@ module JSONAPI
152
152
  end
153
153
 
154
154
  def base_url
155
- @base_url ||= request.protocol + request.host_with_port
155
+ @base_url ||= "#{request.protocol}#{request.host_with_port}#{Rails.application.config.relative_url_root}"
156
156
  end
157
157
 
158
158
  def resource_klass_name
@@ -189,7 +189,7 @@ module JSONAPI
189
189
  end
190
190
  end
191
191
 
192
- def media_types_for(header)
192
+ def media_types_for(header)
193
193
  (request.headers[header] || '')
194
194
  .scan(MEDIA_TYPE_MATCHER)
195
195
  .to_a
@@ -18,7 +18,7 @@ module JSONAPI
18
18
  :default_paginator,
19
19
  :default_page_size,
20
20
  :maximum_page_size,
21
- :default_processor_klass,
21
+ :default_processor_klass_name,
22
22
  :use_text_errors,
23
23
  :top_level_links_include_pagination,
24
24
  :top_level_meta_include_record_count,
@@ -110,7 +110,7 @@ module JSONAPI
110
110
 
111
111
  # The default Operation Processor to use if one is not defined specifically
112
112
  # for a Resource.
113
- self.default_processor_klass = JSONAPI::Processor
113
+ self.default_processor_klass_name = 'JSONAPI::Processor'
114
114
 
115
115
  # Allows transactions for creating and updating records
116
116
  # Set this to false if your backend does not support transactions (e.g. Mongodb)
@@ -225,9 +225,19 @@ module JSONAPI
225
225
  end
226
226
 
227
227
  def default_processor_klass=(default_processor_klass)
228
+ ActiveSupport::Deprecation.warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.')
228
229
  @default_processor_klass = default_processor_klass
229
230
  end
230
231
 
232
+ def default_processor_klass
233
+ @default_processor_klass ||= default_processor_klass_name.safe_constantize
234
+ end
235
+
236
+ def default_processor_klass_name=(default_processor_klass_name)
237
+ @default_processor_klass = nil
238
+ @default_processor_klass_name = default_processor_klass_name
239
+ end
240
+
231
241
  def allow_include=(allow_include)
232
242
  ActiveSupport::Deprecation.warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.')
233
243
  @default_allow_include_to_one = allow_include
@@ -101,6 +101,7 @@ module JSONAPI
101
101
  include_directives,
102
102
  find_options)
103
103
 
104
+ fail JSONAPI::Exceptions::RecordNotFound.new(id) if resource_set.resource_klasses.empty?
104
105
  resource_set.populate!(serializer, context, find_options)
105
106
 
106
107
  return JSONAPI::ResourceSetOperationResult.new(:ok, resource_set, result_options)
@@ -391,7 +392,7 @@ module JSONAPI
391
392
  primary_resource_id_tree = PrimaryResourceIdTree.new
392
393
  primary_resource_id_tree.add_resource_fragments(fragments, include_related)
393
394
 
394
- load_included(resource_klass, primary_resource_id_tree, include_related, options.except(:filters, :sort_criteria))
395
+ load_included(resource_klass, primary_resource_id_tree, include_related, options)
395
396
 
396
397
  primary_resource_id_tree
397
398
  end
@@ -405,7 +406,7 @@ module JSONAPI
405
406
  primary_resource_id_tree = PrimaryResourceIdTree.new
406
407
  primary_resource_id_tree.add_resource_fragments(fragments, include_related)
407
408
 
408
- load_included(resource_klass, primary_resource_id_tree, include_related, options.except(:filters, :sort_criteria))
409
+ load_included(resource_klass, primary_resource_id_tree, include_related, options)
409
410
 
410
411
  primary_resource_id_tree
411
412
  end
@@ -421,7 +422,7 @@ module JSONAPI
421
422
  primary_resource_id_tree = PrimaryResourceIdTree.new
422
423
  primary_resource_id_tree.add_resource_fragments(fragments, include_related)
423
424
 
424
- load_included(resource_klass, primary_resource_id_tree, include_related, options.except(:filters, :sort_criteria))
425
+ load_included(resource_klass, primary_resource_id_tree, include_related, options)
425
426
 
426
427
  primary_resource_id_tree
427
428
  end
@@ -433,7 +434,7 @@ module JSONAPI
433
434
  relationship = resource_klass._relationship(key)
434
435
  relationship_name = relationship.name.to_sym
435
436
 
436
- find_related_resource_options = options.dup
437
+ find_related_resource_options = options.except(:filters, :sort_criteria, :paginator)
437
438
  find_related_resource_options[:sort_criteria] = relationship.resource_klass.default_sort
438
439
  find_related_resource_options[:cache] = resource_klass.caching?
439
440
 
@@ -131,7 +131,7 @@ module JSONAPI
131
131
  def config_description(resource_klass)
132
132
  {
133
133
  class_name: self.class.name,
134
- seriserialization_options: serialization_options.sort.map(&:as_json),
134
+ serialization_options: serialization_options.sort.map(&:as_json),
135
135
  supplying_attribute_fields: supplying_attribute_fields(resource_klass).sort,
136
136
  supplying_relationship_fields: supplying_relationship_fields(resource_klass).sort,
137
137
  link_builder_base_url: link_builder.base_url,
@@ -47,7 +47,6 @@ module JSONAPI
47
47
  )
48
48
  )
49
49
  else
50
- missed_resource_ids[resource_klass] ||= {}
51
50
  missed_resource_ids[resource_klass] = @resource_klasses[resource_klass].keys
52
51
  end
53
52
  end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.10.0.beta8'
3
+ VERSION = '0.10.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.beta8
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gebhardt
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-19 00:00:00.000000000 Z
12
+ date: 2021-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.5'
20
+ version: '1.17'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.5'
27
+ version: '1.17'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -240,15 +240,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
240
  requirements:
241
241
  - - ">="
242
242
  - !ruby/object:Gem::Version
243
- version: '2.1'
243
+ version: '2.3'
244
244
  required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  requirements:
246
- - - ">"
246
+ - - ">="
247
247
  - !ruby/object:Gem::Version
248
- version: 1.3.1
248
+ version: '0'
249
249
  requirements: []
250
- rubyforge_project:
251
- rubygems_version: 2.7.6
250
+ rubygems_version: 3.2.3
252
251
  signing_key:
253
252
  specification_version: 4
254
253
  summary: Easily support JSON API in Rails.