138 Commits

Author SHA1 Message Date
Johannes Vetter
d7f6963afc Links on a relationship can take a callable 2021-01-16 11:45:37 -08:00
nattfodd
f8255771dc Raise FastJsonapi scoped error in case of unsupported include 2020-09-18 13:12:41 +03:00
Donatas Povilaitis
1bcf8d2cb5
Do not add empty relationships key (#116) 2020-09-01 20:44:08 +01:00
Stas SUȘCOV
72f3ae64dd Remove skylight and old instrumentation support. 2020-08-30 15:57:07 +01:00
Stas SUȘCOV
5538555537 Detect enumerables strictly. Closes #112 2020-08-27 11:51:38 +01:00
Stas SUȘCOV
4d1a764abc Updated cache options helper.
Allow extra arguments to improve the API interface.
2020-08-27 11:51:15 +01:00
Kapil Sachdev
c32358ecf5 fix: Rename FastJsonapi::ObjectSerializer to JSONAPI::Serializer
As the project has been renamed, its better to reflect it in the source 
code as well.
JSONAPI::Serializer is evaluated from FastJsonapi::ObjectSerializer so 
this change  probably will go unnoticed in gem usage.
2020-08-27 10:57:15 +01:00
Matthew Newell
8401d16c2e Fix cache keys to prevent fieldset caching errors
This change alters the cache namespace prior to retrieving cached record
data to ensure that different fieldsets are given different cache keys.

Previously, all cache keys for the same record would be specified
identically, leading to a situation where the fieldset would be ignored
if record caching is enabled.

Fixes #90.
2020-08-11 12:54:57 +01:00
Stas SUȘCOV
1ce4677a22
Docs for how the new parsing of includes works. 2020-08-07 12:45:13 +01:00
Nathaniel Bibler
2a946c7723 Use Ruby's safe navigation for Rubocop 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
51b319def5 Remove unused variable 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
593e8ea4e6 Reduce relationship lookups 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
e2ac01f98a Use a Set for managing uniqueness behavior 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
a4bd5a1edc Remove exponential increase in nested includes 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
f62a5bf162 Remove a looped conditional and #blank? use 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
430a5ca2ac Remove unnecessary sort 2020-08-07 12:36:29 +01:00
Nathaniel Bibler
84cd54bd0e Relocate highly-repetitive relationship check 2020-08-07 12:36:29 +01:00
mperice
dd7f5ba415
Add optional meta field to relationships (#99) (#100)
* Add optional meta field to relationships (#99)

* Fix Rubocop's warnings.

* Minor syntax corrections.
2020-07-07 15:22:25 +01:00
Stas SUȘCOV
77d622e4a8 Renamed. Added an alias for now... 2020-06-22 14:47:59 +01:00
Kevin Pheasey
3ff69ccce1
Remove ObjectSerializer#serialized_json (#91)
* chore(ObjectSerializer): remove deprecated serialized_json
* update CHANGELOG.md
2020-06-09 14:03:15 +01:00
Kevin Pheasey
7e2289006c chore(version): release 1.7.2 2020-05-18 11:21:44 -04:00
Kevin Pheasey
1d2eab2510
fix(Relationship): do not set static_record_type for polymorphic relationships (#82) 2020-05-18 10:09:58 -04:00
Kevin Pheasey
b64a0ceeed
fix(ObjectSerializer): pass to_json arguments (#80)
* fix(ObjectSerializer): pass to_json arguments

to_json takes arguments that serialized_json did not define.  This breaks a lot of things.

* Update CHANGELOG.md with latest fix and release
2020-05-01 09:02:03 -04:00
Stas SUȘCOV
c533634293 Rewrite tests. 2020-04-29 15:30:44 +01:00
Stas SUȘCOV
12e2987420 Rubocop cleanups. 2020-04-29 15:30:44 +01:00
Stas SUȘCOV
297551c551 Version bump. Updated the changelog. 2020-04-29 14:35:11 +01:00
Mark Siemers
0edebd99e6 Check #each instead of #size for is_collection?
See if a resource responds to 'each' instead of 'size' as
things other than collections can respond to 'size' (e.g. File instance)
2020-04-11 12:48:00 +01:00
Markus
990c0acd18
Fix attribute API with lambda (#67)
* add failing spec when attribute is called with lambda
* allow to pass a lambda to `attribute`
2020-02-27 17:49:02 +00:00
Markus
843d943e07
Refactor caching support (#52)
- Very explicit where caching is stored
- No `Rails.cache` automagic with possible colliding keys
- Rails 5.2+ cache versioning support
- Implicit namespace support (by cache instance, e.g.
  ActiveSupport::Cache::MemoryStore.new(namespace: 'jast_jsonapi')
- All cache instance options are supported
2020-02-25 16:49:02 +00:00
Attila Horvath
3faca2d1e0 Fix conditional procedures with lambdas 2020-02-21 14:36:50 +00:00
Attila Horvath
08a20d0ebb Fix relationships with &:proc shorthands 2020-02-20 13:44:18 +00:00
Stas SUȘCOV
1b3d73cbf3
Remove multi-to-json. Add a deprecation warning. 2020-02-15 15:05:06 +00:00
Christopher Sansone
6d01bec146
Improved relationship serializer options (#32)
* allow the relationship's serializer key to be a Proc

* fixes

* specifically test the relationship name and the resource type

* support object blocks without a serializer defined

* stop validation gracefully if the relationship is polymorphic

* improve performance by using instance variables instead of accessor methods

* force initialization up front to avoid the iterative calls

* serializer procs should act like polymorphic when determining the id_method_name

* specs for serializer procs

* updated with more details and examples for relationship serializer options

* adjust specs to define the serializers

* avoid extra method calls for performance

* name change

* one less function call for better performance

* do not require lazy loaded relationships to resolve the serializer

* give polymorphic precedence for backwards compatibility

* move serializer inference into ObjectSerializer to allow for overriding

* move method for better diff

* fix race condition in multi-threaded environments
2020-02-15 14:57:44 +00:00
Aubrey Holland
1d7c18f5da Support for polymorphic id_method_name (#17)
* fix id method bugs, add specs
* Use SecureRandom.uuid
2019-12-03 18:04:04 +00:00
Kevin Pheasey
1cd3f97485 1.6.0 2019-11-04 17:31:35 -05:00
Brad Grzesiak
ddc261d8dc Allow "if: Proc..." on link (#15) 2019-10-25 09:32:56 -04:00
Henning Vogt
587fb2c5fe Add params to set_id block (#16)
* Add params to set_id block arguments

Pull request #331 added a block to the ObjectSerializer.set_id class
method, which allows passing a block to the set_id method. Currently
this block takes only one argument `record`:

```
set_id do |record|
  "#{record.name.downcase}-#{record.id}"
end
```

This PR adds another argument `params` to the block:

```
set id do |record, params|
  params[:admin] ?  record.id : "#{record.name.downcase}-#{record.id}"
end
```

This customization can be useful in situation where we serve different
clients that may need different IDs. One nice side effect is also that
the `set_id` method has the same method signature as the `attribute`
method.

* Update the README
2019-10-15 14:45:46 -04:00
David Pickart
8e2383128e Include data key when lazy-loaded relationships are specified with includes (#10) 2019-10-08 08:30:21 -04:00
Krzysztof Rybka
f2a1934b76 Use each_with_object instead of Hash[map] 2019-10-04 19:44:17 -04:00
Krzysztof Rybka
44a896dda5 Take items of original array instead of dup and delete 2019-10-04 19:41:22 -04:00
Krzysztof Rybka
e4c65a2567 Move transforms mapping to constant 2019-10-04 12:50:22 -04:00
Krzysztof Rybka
fd17386b51 Map split include_item in-place 2019-10-04 12:50:22 -04:00
Jo Potts
83e99b2923 Allow relationship links to be declared as object method (#2)
* Allow relationship links to be declared as object method

* Relationship links note added to readme
2019-10-04 12:50:22 -04:00
Krzysztof Rybka
f04abfd2fe Compute remaining_items once 2019-10-04 12:50:22 -04:00
Daniel Duke
267b706366 validate all include items instead of just the first 2019-10-04 12:50:22 -04:00
Daniel Illi
8d8e5c3059 Fix error on defining anonymous serializer class, fixes #353 2019-10-04 12:50:22 -04:00
Matt Eddy
21ae4aaa0a Allow fieldsets to specify no attributes/relationships 2019-10-04 12:50:22 -04:00
Danil Pismenny
1a407c0030 [#365] Support frozen array in option 2019-10-04 12:50:22 -04:00
Shishir Kakaraddi
ee76e0c69b bump up version to 1.5 2018-11-03 12:11:56 -07:00
Shishir Kakaraddi
cc7f88843a
Merge pull request #331 from larissa/set-id-block
Allow block for id customization
2018-11-03 11:37:56 -07:00