Commit Graph

121 Commits

Author SHA1 Message Date
Wojciech Wnętrzak
489ebf2132 Added support for :only and :except methods.
It is possible now to filter returned attributes and associations by:

  UserSerializer.new(user, only: [:first_name, :last_name])
  UserSerializer.new(user, except: :first_name)
2013-04-27 21:29:26 +02:00
Wojciech Wnętrzak
82f50ef81f Unify way of calling include_attribute? in attibutes and association methods. 2013-04-20 23:28:33 +02:00
vanstee
a900d31041 Support strings as attribute names
When generating the `_fast_attributes` method, attribute names that
could not be represented as symbols (at least without escaping) would
throw parsing errors.
2013-04-09 00:53:56 -04:00
Steve Klabnik
9551a97464 Revert 37b0690fb8.
This feature causes more problems than it solves.
2013-04-03 17:24:08 -07:00
Prathamesh Sonpatki
75a72b5cc9 Fixed few typos 2013-03-26 20:29:35 +05:30
Kevin Mahoney
2bd447d69d Pass options through when using default serializer 2013-03-22 13:12:33 +00:00
beerlington
e4ad25073d Adding doc for build_json method 2013-03-20 08:14:23 -04:00
beerlington
fd578fcf69 Refactor and consolidate serializer option setup 2013-03-19 22:21:41 -04:00
beerlington
4a13f86961 Reference scope by same name as serialization scope
By default, the serialization scope uses current_user, and you can
now reference the scope as "current_user" in the serializer. If you
override the scope using "serialization_scope" in your controller,
it will use that method name instead.
2013-03-18 14:44:38 -04:00
Sam
ad1d34b2c4 Fix inheritance issues, poison cache if attributes change 2013-03-16 03:45:06 -07:00
twinturbo
bd90af0e49 Remove commented code 2013-03-14 22:41:34 +01:00
twinturbo
b854d49298 Rebase against master 2013-03-14 22:40:46 +01:00
twinturbo
e3888f0a40 Clean up interface inconistency 2013-03-14 22:40:06 +01:00
twinturbo
535a33a33b Have to opt in with #cache_key 2013-03-14 22:40:06 +01:00
twinturbo
e923174a26 #cache_key delegates to #object by default 2013-03-14 22:40:06 +01:00
twinturbo
b4395f281b Add basic caching 2013-03-14 22:40:06 +01:00
Steve Klabnik
6408b73e3c Merge pull request #233 from SamSaffron/fix
Optimised performance for attribute extraction
2013-03-14 14:22:27 -07:00
Sam
710c375088 remove safe guard per discussion with steveklabnik 2013-03-14 14:11:04 -07:00
Sam
08a182d743 per discussion remove instrumentation altogether 2013-03-13 22:18:40 -07:00
Sam
31ba6fbb08 Optimised performance for attribute extraction
Disabled all instrumentation unless enabled explicitly
2013-03-13 21:20:56 -07:00
Michael Rykov
37b0690fb8 Add a Responder to handle respond_with(resource) 2013-03-13 16:45:23 -07:00
Steve Klabnik
e76a16486f Merge pull request #170 from FundingGates/master
Support optional types for computed attributes
2013-03-08 09:11:29 -08:00
Adam Stanton
da26ebd26f Merge branch 'create-default-serializer' into HEAD
Conflicts:
	lib/active_model/array_serializer.rb
2013-03-05 21:48:58 -08:00
Steve Klabnik
06c65871a8 Merge pull request #213 from michihuber/fix_rendering_nil_with_custom_serializer
Fix rendering nil with custom serializer
2013-03-05 15:54:51 -08:00
Steve Klabnik
d638e21c8c Merge pull request #180 from fellix/fix-remove-root-globally
Fix global ``` self.root = false ```
2013-03-05 15:48:08 -08:00
Ismael Abreu
2d2094b588 changes to be able to specify multiple attributes with keys 2013-03-05 02:45:22 +00:00
Nicholas Mulder
fa51c5f574 Add ActiveSupport::DescendantsTracker to Serializer and ArraySerializer 2013-02-28 10:01:40 -05:00
Michi Huber
c7a420d295 Don't fail if object is nil, render null 2013-02-26 11:17:28 +01:00
Adam Stanton
c4fcf96eb4 Move DefaultSerializer from array_serializer.rb to serializer.rb 2013-02-10 09:49:11 -08:00
Rafael Felix
82951c1f8a Fix global `` self.root = false ``
Using the on_load hook does not change the defined root on
Serializer#inherited.

Related to #179
2013-01-24 09:13:41 -02:00
Steve Klabnik
e3bfd07ac4 Merge pull request #161 from kevins90/fix_attr_name_as_serializer_underscored_prefix
Fix serialization of attribute whose name matches the serializer prefix underscored
2013-01-05 14:09:15 -08:00
Matt Rogish
25c564bd6f Adding optional type for attributes 2012-12-10 19:58:58 -05:00
Steve Klabnik
6780cd3df5 Merge pull request #138 from tchak/meta
Meta object
2012-12-10 10:48:39 -08:00
Kevin Tham
14a35ab2f8 Remove unneeded method aliasing of attribute reader: object, with the underscored class name of serializer, to fix issue where a model's attribute name matches that of the underscored prefix of the serializer 2012-11-25 00:17:17 -08:00
Jo Liss
2fc083a1fe Merge pull request #117 from joliss/computed-attributes
Make schema not crash on computed attributes & associations
2012-11-22 08:31:18 -08:00
tchak
a71698d5bb Add support for meta key
Test for meta_key serialization
2012-11-22 13:44:59 +01:00
Samnang Chhun
96ce310595 Add alias_method ActiveModel::Serializer.root= to be consistency with ActiveModel::ArraySerializer 2012-11-20 00:29:00 +07:00
Jo Liss
538b0c0916 Make schema not crash on computed associations
We pick nil here as well.
2012-10-31 20:07:08 +01:00
Jo Liss
6281a9149e Make schema not crash on computed attributes
We do not know the type for computed attributes, so we pick nil.

Perhaps at some point we might add a :type option for attributes (or
not), but in any case it's important to not crash when there are
computed attributes.
2012-10-31 20:07:08 +01:00
Jo Liss
c767d7f5e4 Remove newly-redundant OrderedSet 2012-10-29 23:15:39 +01:00
Jo Liss
ee3cec3d0c When objects are sideloaded multiple times, serialize them only once
To achieve this, we make the following change when sideloading: Instead
of serializing associations and discarding duplicate *hashes*, we
memorize the *objects* (records) that we have already serialized, and
only serialize those that are new.

This change is mostly transparent, and brings down serialization time
from 3.1 seconds to 1.0 seconds on my set of sample data.

There is one change in the behavior: If you sideload the same object
multiple times, and it yields different hashes, like so:

    embed :ids, include: true
    has_many :comments
    has_many :recent_comments, root: comments, serializer: CommentShortSerializer

then previously, it would be included multiple times, whereas now, the
first hash wins. (I haven't actually tested this.) I don't know that
either option is preferable. It's not covered by the test suite, and I
think it's an edge case that is OK to ignore entirely.
2012-10-29 23:15:32 +01:00
Jo Liss
6be6ed8326 Extract Associations module into separate file 2012-10-29 17:21:27 +01:00
Tee Parham
9584b9e147 move OrderedSet to separate file 2012-09-18 01:28:07 +02:00
Tee Parham
b8f01ba2f3 move ArraySerializer to separate file 2012-09-18 01:28:07 +02:00
Yehuda Katz
2130cdfc00 List out the event names to avoid garbage 2012-09-16 20:20:34 -07:00
Yehuda Katz
a025f1b6f6 Eliminate some String garbage 2012-09-16 20:08:30 -07:00
Dan Gebhardt
42221a6140 define include_XXX? methods, which can be overridden to conditionally include attributes and associations 2012-08-29 09:26:41 -04:00
Dan Gebhardt
68dc57eb73 simplified the API for include_associations!() to make conditional includes cleaner 2012-08-29 07:42:23 -04:00
twinturbo
38859d1f3d Easier to work with polymorphic interface 2012-08-25 17:39:39 +02:00
Alex Kwiatkowski & Will Bagby
754aa295ba Return empty hash when url_options not provided 2012-08-07 12:56:58 -04:00