Skip to content

Commit 98a6958

Browse files
authored
Merge pull request #4 from sanger/y25-318-from-master
Y25-318 Publish sanger-jsonapi-resources gem from master
2 parents a3a2a7a + 3100a4b commit 98a6958

16 files changed

+99
-95
lines changed

.github/workflows/ruby.yml

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,26 @@ name: CI
22

33
on:
44
push:
5-
branches: [ 'master', 'release-0-8', 'release-0-9', 'release-0-10' ]
5+
branches: [ 'master' ]
66
pull_request:
77
branches: ['**']
88

99
jobs:
1010
tests:
1111
runs-on: ubuntu-latest
12-
services:
13-
postgres:
14-
image: postgres
15-
env:
16-
POSTGRES_PASSWORD: password
17-
POSTGRES_DB: test
18-
options: >-
19-
--health-cmd pg_isready
20-
--health-interval 10s
21-
--health-timeout 5s
22-
--health-retries 5
23-
ports:
24-
- 5432:5432
2512
strategy:
2613
fail-fast: false
2714
matrix:
2815
ruby:
29-
- 2.6
30-
- 2.7
31-
- '3.0'
32-
- 3.1
33-
- 3.2
16+
- '3.4'
17+
- '3.3'
18+
- '3.2'
3419
rails:
35-
- 7.0.4
36-
- 6.1.7
37-
- 6.0.6
38-
- 5.2.8.1
39-
- 5.1.7
20+
- '7.1'
21+
- '7.0'
22+
- '8.0.2'
4023
database_url:
41-
- postgresql://postgres:password@localhost:5432/test
4224
- sqlite3:test_db
43-
exclude:
44-
- ruby: 3.2
45-
rails: 6.0.6
46-
- ruby: 3.2
47-
rails: 5.2.8.1
48-
- ruby: 3.2
49-
rails: 5.1.7
50-
- ruby: 3.1
51-
rails: 6.0.6
52-
- ruby: 3.1
53-
rails: 5.2.8.1
54-
- ruby: 3.1
55-
rails: 5.1.7
56-
- ruby: '3.0'
57-
rails: 6.0.6
58-
- ruby: '3.0'
59-
rails: 5.2.8.1
60-
- ruby: '3.0'
61-
rails: 5.1.7
62-
- ruby: 2.6
63-
rails: 7.0.4
64-
- database_url: postgresql://postgres:password@localhost:5432/test
65-
rails: 5.1.7
6625
env:
6726
RAILS_VERSION: ${{ matrix.rails }}
6827
DATABASE_URL: ${{ matrix.database_url }}
@@ -73,7 +32,6 @@ jobs:
7332
uses: ruby/setup-ruby@v1
7433
with:
7534
ruby-version: ${{ matrix.ruby }}
76-
- name: Install dependencies
77-
run: bundle install --jobs 4 --retry 3
35+
bundler-cache: true
7836
- name: Run tests
7937
run: bundle exec rake test

Gemfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ version = ENV['RAILS_VERSION'] || 'default'
1010

1111
platforms :ruby do
1212
gem 'pg'
13-
14-
if version.start_with?('4.2', '5.0')
15-
gem 'sqlite3', '~> 1.3.13'
16-
else
17-
gem 'sqlite3', '~> 1.4'
18-
end
13+
gem 'mysql2'
14+
gem 'sqlite3'
15+
gem 'csv'
1916
end
2017

2118
case version
@@ -26,4 +23,4 @@ when 'default'
2623
gem 'railties', '>= 6.0'
2724
else
2825
gem 'railties', "~> #{version}"
29-
end
26+
end

jsonapi-resources.gemspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44
require 'jsonapi/resources/version'
55

66
Gem::Specification.new do |spec|
7-
spec.name = 'jsonapi-resources'
7+
spec.name = 'sanger-jsonapi-resources'
88
spec.version = JSONAPI::Resources::VERSION
9-
spec.authors = ['Dan Gebhardt', 'Larry Gebhardt']
10-
spec.email = ['dan@cerebris.com', 'larry@cerebris.com']
9+
spec.authors = ['PSD Team - Wellcome Trust Sanger Institute']
10+
spec.email = ['psd@sanger.ac.uk']
1111
spec.summary = 'Easily support JSON API in Rails.'
12-
spec.description = 'A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
13-
spec.homepage = 'https://github.com/cerebris/jsonapi-resources'
12+
spec.description = 'Forked from jsonapi-resources. A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
13+
spec.homepage = 'https://github.com/sanger/jsonapi-resources'
1414
spec.license = 'MIT'
1515

1616
spec.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE.txt README.md)

lib/generators/jsonapi/controller_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'rails/generators'
12
module Jsonapi
23
class ControllerGenerator < Rails::Generators::NamedBase
34
source_root File.expand_path('../templates', __FILE__)

lib/generators/jsonapi/resource_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'rails/generators'
12
module Jsonapi
23
class ResourceGenerator < Rails::Generators::NamedBase
34
source_root File.expand_path('../templates', __FILE__)

lib/jsonapi/active_relation_resource.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,14 @@ def find_related_polymorphic_fragments(source_fragments, relationship, options,
666666
end
667667

668668
relation_position = relation_positions[row[2].downcase.pluralize]
669-
model_fields = relation_position[:model_fields]
670-
cache_field = relation_position[:cache_field]
671-
cache_offset = relation_position[:cache_offset]
672-
field_offset = relation_position[:field_offset]
669+
if relation_position
670+
model_fields = relation_position[:model_fields]
671+
cache_field = relation_position[:cache_field]
672+
cache_offset = relation_position[:cache_offset]
673+
field_offset = relation_position[:field_offset]
674+
else
675+
next # Skip processing if relation_position is nil
676+
end
673677

674678
if cache_field
675679
related_fragments[rid].cache = cast_to_attribute_type(row[cache_offset], cache_field[:type])

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'csv'
4-
4+
require_relative 'compatibility_helper'
55
module JSONAPI
66
module ActsAsResourceController
77
MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
@@ -63,16 +63,16 @@ def index_related_resources
6363

6464
def get_related_resource
6565
# :nocov:
66-
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resource`"\
67-
" action. Please use `show_related_resource` instead."
66+
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resource`"\
67+
" action. Please use `show_related_resource` instead.")
6868
show_related_resource
6969
# :nocov:
7070
end
7171

7272
def get_related_resources
7373
# :nocov:
74-
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resources`"\
75-
" action. Please use `index_related_resources` instead."
74+
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resources`"\
75+
" action. Please use `index_related_resources` instead.")
7676
index_related_resources
7777
# :nocov:
7878
end

lib/jsonapi/basic_resource.rb

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

33
require 'jsonapi/callbacks'
44
require 'jsonapi/configuration'
5-
5+
require_relative 'compatibility_helper'
66
module JSONAPI
77
class BasicResource
88
include Callbacks
@@ -547,7 +547,7 @@ def attribute(attribute_name, options = {})
547547
check_reserved_attribute_name(attr)
548548

549549
if (attr == :id) && (options[:format].nil?)
550-
ActiveSupport::Deprecation.warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.')
550+
JSONAPI::CompatibilityHelper.deprecation_warn('Id without format is deprecated. Please specify a format for the id attribute.')
551551
end
552552

553553
check_duplicate_attribute_name(attr) if options[:format].nil?
@@ -609,11 +609,12 @@ def has_one(*attrs)
609609
end
610610

611611
def belongs_to(*attrs)
612-
ActiveSupport::Deprecation.warn "In #{name} you exposed a `has_one` relationship "\
612+
613+
JSONAPI::CompatibilityHelper.deprecation_warn( "In #{name} you exposed a `has_one` relationship "\
613614
" using the `belongs_to` class method. We think `has_one`" \
614615
" is more appropriate. If you know what you're doing," \
615616
" and don't want to see this warning again, override the" \
616-
" `belongs_to` class method on your resource."
617+
" `belongs_to` class method on your resource.")
617618
_add_relationship(Relationship::ToOne, *attrs)
618619
end
619620

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
# JSONAPI::CompatibilityHelper
4+
#
5+
# This module provides a version-safe method for issuing deprecation warnings
6+
# that works across multiple versions of Rails (7.x, 8.x, etc).
7+
#
8+
# Usage:
9+
# JSONAPI::CompatibilityHelper.deprecation_warn("Your deprecation message")
10+
#
11+
# The method will use the public `warn` method if available, otherwise it will
12+
# use `send(:warn, ...)` to maintain compatibility with Rails 8+ where `warn`
13+
# is private.
14+
#
15+
# Example:
16+
# JSONAPI::CompatibilityHelper.deprecation_warn("This feature is deprecated.")
17+
18+
module JSONAPI
19+
module CompatibilityHelper
20+
def deprecation_warn(message)
21+
if ActiveSupport::Deprecation.respond_to?(:warn) && ActiveSupport::Deprecation.public_method_defined?(:warn)
22+
ActiveSupport::Deprecation.warn(message)
23+
else
24+
ActiveSupport::Deprecation.send(:warn, message)
25+
end
26+
end
27+
module_function :deprecation_warn
28+
end
29+
end

lib/jsonapi/configuration.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'jsonapi/formatter'
44
require 'jsonapi/processor'
55
require 'concurrent'
6-
6+
require_relative 'compatibility_helper'
77
module JSONAPI
88
class Configuration
99
attr_reader :json_key_format,
@@ -227,7 +227,7 @@ def exception_class_allowed?(e)
227227
end
228228

229229
def default_processor_klass=(default_processor_klass)
230-
ActiveSupport::Deprecation.warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.')
230+
JSONAPI::CompatibilityHelper.deprecation_warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.')
231231
@default_processor_klass = default_processor_klass
232232
end
233233

@@ -241,18 +241,18 @@ def default_processor_klass_name=(default_processor_klass_name)
241241
end
242242

243243
def allow_include=(allow_include)
244-
ActiveSupport::Deprecation.warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.')
244+
JSONAPI::CompatibilityHelper.deprecation_warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.')
245245
@default_allow_include_to_one = allow_include
246246
@default_allow_include_to_many = allow_include
247247
end
248248

249249
def whitelist_all_exceptions=(allow_all_exceptions)
250-
ActiveSupport::Deprecation.warn('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`')
250+
JSONAPI::CompatibilityHelper.deprecation_warn('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`')
251251
@allow_all_exceptions = allow_all_exceptions
252252
end
253253

254254
def exception_class_whitelist=(exception_class_allowlist)
255-
ActiveSupport::Deprecation.warn('`exception_class_whitelist` has been replaced by `exception_class_allowlist`')
255+
JSONAPI::CompatibilityHelper.deprecation_warn('`exception_class_whitelist` has been replaced by `exception_class_allowlist`')
256256
@exception_class_allowlist = exception_class_allowlist
257257
end
258258

0 commit comments

Comments
 (0)