68 Commits

Author SHA1 Message Date
Stas SUȘCOV
12e2987420 Rubocop cleanups. 2020-04-29 15:30:44 +01: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
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
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
44a896dda5 Take items of original array instead of dup and delete 2019-10-04 19:41:22 -04:00
Krzysztof Rybka
fd17386b51 Map split include_item in-place 2019-10-04 12:50:22 -04:00
Krzysztof Rybka
f04abfd2fe Compute remaining_items once 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
Larissa Reis
9fa26fa588 Allow block for id customization
Allow an ID of object to be customized directly on the serializer by
passing a block to `set_id` as opposed to only through a model property.

We already allow for attributes that do not have a model property of the
same name to be customized directly on the serializer using a block.

This customization can be useful in situation in which you have
different classes being serialized using the same serializer. For
example, if we have `HorrorMovie`, `ComedyMovie` and `DramaMovie` using
the same `MovieSerializer`, we can unify their IDs using

```
class MovieSerializer
  include FastJsonapi::ObjectSerializer

  attributes :name, :year
  set_id do |record|
    "#{record.name.downcase}-#{record.id}"
  end
```

which is preferable to creating a `#serialized_id` method in every model
that will use `MovieSerializer` to encapsulate the customization.

Closes #315
2018-10-10 22:26:57 -06:00
François Pradel
955f4f234d Add support for polymorphic includes 2018-08-31 19:17:45 -07:00
Igor Khodyrev
e3c45d9b1b Fix weak entities case (id is not meaningful attribute) with include. 2018-08-22 20:05:51 -07:00
Manoj M J
099eb606bd
Merge branch 'dev' into add_meta 2018-07-21 09:39:33 +05:30
Shishir Kakaraddi
40125072c5
Merge pull request #278 from TrevorHinesley/params-in-nested-includes
Params are now passed to nested includes
2018-07-20 19:16:23 -07:00
Erol
e1f782e79f Add missing fieldset parameter 2018-07-20 18:49:51 -07:00
Manoj M J
dd71bc15d6 Introduce the ability to add meta tag for every resource in the collection 2018-07-20 10:33:27 +05:30
Trevor Hinesley
dfcbe263fb
Merge branch 'master' into params-in-nested-includes 2018-07-19 09:58:25 -05:00
Trevor Hinesley
07b6e614ac Params are now passed to nested includes 2018-07-19 09:57:22 -05:00
Erol
fa194133fa Use record type instead of reflected record type 2018-07-16 21:10:10 -07:00
Erol
ab652c4400 Remove unused code 2018-07-16 21:10:10 -07:00
Erol
a363c90bfb Allow the serializer to return sparse fieldsets 2018-07-16 21:10:10 -07:00
Erol
5905497314 Use record type instead of reflected record type 2018-07-16 21:07:57 -07:00
Erol
5aa5dc511c Remove unused code 2018-07-16 21:07:57 -07:00
Erol
7b44620018 Allow the serializer to return sparse fieldsets 2018-07-16 21:07:57 -07:00
Kyle Reeves
699630d812 create link class 2018-07-03 19:33:34 -07:00
Kyle Reeves
f86a8926f5 make include_relationship? a public method and use it in get_included_records method 2018-07-03 19:33:34 -07:00
Kyle Reeves
6e7d8b7ee0 make fetch_associated_object a public method on relationship class so it can be called from SerilizationCore class 2018-07-03 19:33:34 -07:00
Kyle Reeves
22d412246f WIP 2018-07-03 19:33:34 -07:00
Kyle Reeves
7b23adddc4 working on new relationship class 2018-07-03 19:33:34 -07:00
Trevor Hinesley
f864099761 Conditional relationships should be removed from included when proc evaluates to false 2018-07-03 19:33:34 -07:00
Kyle Reeves
5558dcd703 allow conditional relationships 2018-07-03 19:33:34 -07:00
Trevor Hinesley
5c820695b3 Split attribute serialization into its own class 2018-06-21 18:38:42 -07:00
Trevor Hinesley
bad004fd42 Allow conditional attributes 2018-06-21 18:38:42 -07:00
homer
44d5e0f9c5 Fix serialization for nested nil includes with block 2018-05-31 17:16:54 -07:00
Shishir Kakaraddi
cd1bc0968e dont create a object for a has one relationship unnecessarily just to fetch id 2018-05-20 15:11:07 -07:00
Shishir Kakaraddi
ea5296ac25 making object level links similar to attributes 2018-05-20 15:08:47 -07:00
Jodi Showers
74f27ccdf0 Links within data (#161) 2018-05-20 13:14:46 -07:00
Ryan O'Donnell
b090391551 Fix serialization for nested nil includes 2018-05-18 19:06:16 -07:00
Shishir Kakaraddi
00d3aa4997 adding NotImplementedError when trying to include polymorphic relationships 2018-05-10 23:22:21 -07:00
Shishir Kakaraddi
d7f5c34404 fixes a syntax error 2018-05-10 22:13:59 -07:00
Jodi Showers
3ebf34928c Serialize nested includes (#152) 2018-05-10 21:17:32 -07:00
Shishir Kakaraddi
63f905ab36 adds params to relatinoship blocks and tests 2018-05-08 22:11:22 -07:00
Shuhei Kitagawa
e39de8c8c4 Enable to use block to define relationship 2018-05-06 10:26:38 -07:00
Zino
f4f289a0bc Remove duplicate id_hash call from #record_hash 2018-05-03 20:50:03 -07:00
Brandon Buck
a585497161 Add in options[:scope] and receiving scope in attribute blocks (#153) 2018-05-01 09:58:01 -07:00
Dillon Welch
1b3b533b40 Don't allocate variables if we're not going to use them 2018-04-26 19:33:20 -07:00
Dillon Welch
da275e189d Add default hash option to id_hash 2018-04-26 19:33:20 -07:00
Dillon Welch
ca0f600ed9 Use id_hash method instead of duplicating logic 2018-04-26 19:33:20 -07:00