Commit Graph

160 Commits

Author SHA1 Message Date
Gabe da Silveira
36d92804ed Fix serializer.as_json(nil)
This is the form that ActiveSupport 3.1 Object#to_json invokes.
2013-12-30 12:36:18 -06:00
Steve Klabnik
48e5ca29f1 Add Coveralls for code coverage. 2013-05-05 13:38:56 -07:00
Steve Klabnik
bb8900e308 Merge pull request #264 from vad4msiu/features/root_element
Support for setting root element
2013-05-05 12:02:27 -07:00
Steve Klabnik
cffdbce072 Merge pull request #283 from morgoth/add-only-and-except-options-support
Add only and except options support
2013-05-05 12:00:59 -07:00
Gosha Arinich
1482081766 add support of mongoid collection serialization 2013-05-05 21:50:34 +03:00
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
vanstee
ef6ab5f0c0 Switch back to the old hash syntax
Just fixed up a couple of hash literals in the tests so that the build
passes for 1.8.7
2013-04-16 22:55:57 -04:00
Steve Klabnik
c1dacccbdc Merge pull request #273 from seanabrahams/embed-ids-not-using-local-method
Fixes #267
2013-04-15 17:44:06 -07:00
Sean Abrahams
79acd87829 Use method instead of asssociation_ids if method exists. Fixes #267 2013-04-10 14:38:53 -07:00
Sean Abrahams
a771f30816 If output is as expected, is this assert important? 2013-04-10 14:36:42 -07: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
vad4msiu
95081410d2 Support for setting root element 2013-04-04 15:10:29 +04:00
Steve Klabnik
ab5d40f38b Sigh.
When I did 9551a97464, I
forgot that some new code may use it.
2013-04-03 23:56:06 -07:00
Steve Klabnik
9551a97464 Revert 37b0690fb8.
This feature causes more problems than it solves.
2013-04-03 17:24:08 -07:00
Prathamesh Sonpatki
f6cf469820 Fix failing tests for edge rails
* Edge Rails returns an instance of 'Gem::Version' for 'Rails.version' due to e600384515dc06db2c56ff5be5c18779f7b379a5
 * Travis build was failing because of this as 'Rails.version.start_with? '4'' was giving 'undefined method' on 'Gem::Version' instance
2013-03-27 10:29:36 +05:30
Prathamesh Sonpatki
75a72b5cc9 Fixed few typos 2013-03-26 20:29:35 +05:30
Steve Klabnik
c129ae2016 Generate id method on Ruby 1.8.
Because object_id and id went through some flux, it's best to tell 1.8
specifically what we mean.

Closes #127.
2013-03-19 14:53:08 -07: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
Bartek Borkowski
00b5739d38 Add mutual association test 2013-03-15 18:59:05 +01:00
Steve Klabnik
746a63ab09 Merge pull request #89 from twinturbo/caching
Serializers Cache JSON & Hashes
2013-03-15 10:30:04 -07:00
Tony Pitale
d3c6596990 make sure to merge the original responder options into the given options to preserve location 2013-03-15 03:54:35 -04:00
twinturbo
4a5e1e1ae5 Attemp to fix bad test 2013-03-15 08:41:39 +01:00
twinturbo
c3966fe741 ArraySerializer is also cached 2013-03-14 22:54:05 +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
Michael Rykov
37b0690fb8 Add a Responder to handle respond_with(resource) 2013-03-13 16:45:23 -07:00
Steve Klabnik
f4916f113f Merge pull request #223 from tchak/id-serialization-with-hooks
use `read_attribute_for_serialization` to serialize ids
2013-03-08 09:17:19 -08: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
tchak
e2c10f4440 use read_attribute_for_serialization to serialize ids
* in order to allow some optimisation in simple cases, we call `read_attribute_for_serialization` on parent with association_id name
2013-03-08 09:57:42 +01: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
dc2257977f Merge pull request #198 from jredburn/master
'embed_key' option to allow embedding by attributes other than IDs
2013-03-05 15:57:34 -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
Jeremy Redburn
7cd7d295e0 Adding 'embed_key' option to allow embedding attributes other than ID 2013-03-05 18:52:31 -05: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
Steve Klabnik
95937c6fc7 Merge pull request #167 from GateGuru/feature/specify-association-serializers-as-strings
Add support for specifying the serializer for an association as a String...
2013-03-05 15:04:29 -08:00
Ismael Abreu
2d2094b588 changes to be able to specify multiple attributes with keys 2013-03-05 02:45:22 +00:00
Michi Huber
c7a420d295 Don't fail if object is nil, render null 2013-02-26 11:17:28 +01:00
Michi Huber
58a063eff0 serialization test: respect root settings when root object is nil 2013-02-26 11:12:28 +01:00
Adam Stanton
b4616d737c Restore order of fields in hash to original order. 2013-02-11 07:04:59 -08:00
Adam Stanton
c4fcf96eb4 Move DefaultSerializer from array_serializer.rb to serializer.rb 2013-02-10 09:49:11 -08:00
Adam Stanton
8f6218c587 Create DefaultSerializer so that as_json uses same interface.
This is to ensure that PORO's as_json is called if no serializer
is specified.

Original behaviour was that serializable_hash was being called,
overriding the as_json method.
2013-02-10 09:06:24 -08:00
Lee Mallabone
d35999a7ee Add failing test to show behavior of custom serializer with nils. 2013-02-06 17:32:15 -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
Blake Watters
b0aced9ea2 Add support for specifying the serializer for an association as a String.
This enables the deferral of the resolution of the serializer class to prevent NameError exceptions due to reference cycles between serializer classes.
2013-01-05 23:49:28 -05: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
Dan Gebhardt
3b1d2faf51 Append an _id or _ids suffix to associations' keys. Embed objects in root according to their serializers' names.
An `_id` suffix will be appended to the name of HasOne associations, while `_ids` will be appended to the singularized name of HasMany associations. Association keys can still be overridden with the `key` option.

Furthermore, objects embedded in the root are now by default named according to their serializer, instead of the key used for their associations.
2012-12-21 15:14:50 -05:00
Jérémy Lecour
c68a18630b Test : use a deducted serializer on non-ActiveRecord models 2012-12-20 17:06:19 +01:00