Santiago Pastorino
4ab16381bd
Bump version to 0.9.0.pre
2013-10-18 17:49:22 -02:00
Santiago Pastorino
73774649e3
Implement Generators
2013-10-18 17:49:21 -02:00
Santiago Pastorino
91f9317713
There's no need to define read_attribute_for_serialization in the Serializer class
2013-10-18 17:49:21 -02:00
Santiago Pastorino
b9a6dfac2f
Do not call send on associated objects, do it through elem.read_attribute_for_serialization
2013-10-18 17:49:21 -02:00
Santiago Pastorino
4b91d0e5ec
embed :objects is the default
...
A commit with an integration test that covers this functionality is
coming after this one
2013-10-18 17:49:20 -02:00
Santiago Pastorino
4f70dc2091
has_one serialized objects shouldn't be wrapped in an array and it's key is singular
2013-10-18 17:49:20 -02:00
Santiago Pastorino
dbf512c14c
Make embed nil ids work
2013-10-18 17:49:20 -02:00
Santiago Pastorino
cad8fafa60
Optimize serializer_for for Ruby >= 2.0
2013-10-18 17:49:20 -02:00
Santiago Pastorino
841f3b8181
Add filter to allow users implement filter method to include/exclude attributes and relations
2013-10-18 17:49:20 -02:00
Santiago Pastorino
f6ea07dd22
Do not convert attrs to String until needed
2013-10-18 17:49:20 -02:00
Santiago Pastorino
daa9304398
Do not convert root and meta_key to Strings
2013-10-18 17:49:20 -02:00
Santiago Pastorino
75e9a2599d
Store attributes as they are instead of converting them into Strings
2013-10-18 17:49:20 -02:00
Santiago Pastorino
10e882a14f
Allow to set embed options from AM::Serializer
2013-10-18 17:49:20 -02:00
Santiago Pastorino
aa23e811cc
Use controller name as root when serializing an array and not root is defined
2013-10-18 17:49:20 -02:00
Santiago Pastorino
86b9d5a226
Avoid work inside serializable_array
2013-10-18 17:49:20 -02:00
Santiago Pastorino
8006529e20
Allow ArraySerializer to pass the options down to item serializers
2013-10-18 17:49:19 -02:00
Santiago Pastorino
6f3503c965
Use serializer name as root when root not set
2013-10-18 17:49:19 -02:00
Santiago Pastorino
626a85bc3e
Allow using root = false in initialize
2013-10-18 17:49:19 -02:00
Santiago Pastorino
7405baafd7
Serialize associations that doesn't have an associated serializer
2013-10-18 17:49:19 -02:00
Santiago Pastorino
513e7f2166
Add setup method and Setting object to configure AMS
2013-10-18 17:49:19 -02:00
Santiago Pastorino
0e0341effc
Implement embed in root
2013-10-18 17:49:19 -02:00
Santiago Pastorino
af34adc7b5
Move key's initialization code to initializers
2013-10-18 17:49:19 -02:00
Santiago Pastorino
280fd65db8
Allow to set key for associations through options
2013-10-18 17:49:19 -02:00
Santiago Pastorino
48590a2e37
Allow to set root for associations through options
2013-10-18 17:49:19 -02:00
Santiago Pastorino
8a495b1d00
Embedded has_one returns an array with the key pluralized
2013-10-18 17:49:19 -02:00
Santiago Pastorino
3fcd8c5f98
Define root and root= as aliases of _root=
2013-10-18 17:49:18 -02:00
Santiago Pastorino
7ba05c02e3
Make Serializable module which implements as_json
2013-10-18 17:49:18 -02:00
Santiago Pastorino
e6993c677b
Add missing requires
2013-10-18 17:49:18 -02:00
Santiago Pastorino
a820e9774f
Add ArraySerializer's root and meta features
2013-10-18 17:49:18 -02:00
Santiago Pastorino
70ea6c6bc7
Add has_one and has_many :serialize => tests
2013-10-18 17:49:18 -02:00
Santiago Pastorino
f647b7ae74
Implement each_serializer
2013-10-18 17:49:18 -02:00
Santiago Pastorino
7e83f0c29d
Implement ArraySerializer
2013-10-18 17:49:18 -02:00
Santiago Pastorino
61a1669a86
Implement has_many
2013-10-18 17:49:18 -02:00
Santiago Pastorino
516f5bdceb
Implement has_one's embed ids include true
2013-10-18 17:49:18 -02:00
Santiago Pastorino
52bb3f6929
Implement has_one's embed objects
2013-10-18 17:49:17 -02:00
Santiago Pastorino
d756ae4a70
Implement has_one's and serialize_ids
2013-10-18 17:49:17 -02:00
Santiago Pastorino
01bc534976
Remove SerializerSupport
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0d4dfb69a9
Fix directories the project is on top level dir
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0c91564101
Remove method redefined warning
2013-10-18 17:49:17 -02:00
Santiago Pastorino
9e75625b1f
Re-order properties
2013-10-18 17:49:17 -02:00
Santiago Pastorino
93baaa96b1
Implement meta and meta_key for AM::Serializer
2013-10-18 17:49:17 -02:00
Santiago Pastorino
d41e5ccef7
Implement SerializerSupport class
2013-10-18 17:49:17 -02:00
Santiago Pastorino
b6f9c5ee43
Implement Serializer's scope
2013-10-18 17:49:16 -02:00
Santiago Pastorino
c3f857d1b6
Implement Serializer's root
2013-10-18 17:49:16 -02:00
Santiago Pastorino
7143eb8301
Serialize just attributes
2013-10-18 17:49:16 -02:00
Santiago Pastorino
14f51f2ea9
Remove everything, rewrite of AMS starts here
2013-10-18 17:46:18 -02:00
Tee Parham
74ba9dc76c
upgrade hash syntax
2013-05-30 15:25:06 -06:00
Santiago Pastorino
c97acfd9ba
Always set a serializer for each item of an Array
...
model.active_model_serializer could return nil so we need to ensure that
if serializer is not setted we set DefaultSerializer to it.
This reverts commit 64ed05c484 .
Fixes #318
2013-05-28 18:13:07 -07:00
Santiago Pastorino
f68003f64d
Merge pull request #313 from geigerzaehler/fix_root
...
Don't wrap array items in root element
2013-05-24 14:49:41 -07:00
Santiago Pastorino
9521e912fe
serialize_ids call methods on the corresponding serializer if defined
2013-05-24 14:09:27 -07:00
Thomas Scholtes
258248d6c0
Don't wrap array items in root element
2013-05-24 10:23:59 +02:00
Santiago Pastorino
ee846f39af
Fix build in 1.8.7
2013-05-22 14:24:22 -07:00
Damian Galarza
bbc3ae44cc
Allow a controller to properly override scope_name
2013-05-21 21:24:50 -04:00
Santiago Pastorino
35608a8550
Move version.rb file to serializer directory
2013-05-21 17:03:09 -07:00
Santiago Pastorino
055f8fe33c
AMS::Associations::Base is now AMS::Association. HasMany and HasOne inherits from it.
2013-05-21 17:03:08 -07:00
Santiago Pastorino
787b7cf24a
Document Associations
2013-05-21 17:03:08 -07:00
Santiago Pastorino
0b6326eb35
Move polymorphic to initialize + reader
2013-05-21 17:03:08 -07:00
Santiago Pastorino
36feb5d44f
Refactor embeddable? method
2013-05-21 17:03:08 -07:00
Santiago Pastorino
bbd3c8b157
Define embeddable? as an alias of object
2013-05-21 17:03:08 -07:00
Santiago Pastorino
e295af2e2b
Move embed methods to initialize and define readers
2013-05-21 17:03:08 -07:00
Santiago Pastorino
cd9e106640
All the attr_readers together
2013-05-21 17:03:08 -07:00
Santiago Pastorino
1c3f14407c
There's no need for target_serializer method
2013-05-21 17:03:08 -07:00
Santiago Pastorino
feaefeeef3
Use name reader
2013-05-21 17:03:08 -07:00
Santiago Pastorino
296970415a
Move key method to the base class
2013-05-21 17:03:08 -07:00
Santiago Pastorino
ecbb8bf6a6
Use == || == instead of include?
2013-05-21 17:03:08 -07:00
Santiago Pastorino
eb5b27de69
Initialize things in the initialize method and define readers
2013-05-21 17:03:08 -07:00
Santiago Pastorino
ea6d712cc8
key method is defined on subclasses
2013-05-21 17:03:07 -07:00
Santiago Pastorino
2dd0090f13
Reorder methods
2013-05-21 17:03:07 -07:00
Santiago Pastorino
0b648fceac
Use private instead of protected, we don't use explicit receivers
2013-05-21 17:03:07 -07:00
Santiago Pastorino
f9e189e9d7
Rename associated_object to object
2013-05-21 17:03:07 -07:00
Santiago Pastorino
85bf3d2f3d
Move duplicated code to the Base class
2013-05-21 17:03:07 -07:00
Santiago Pastorino
03669a74bc
Associations::Config is now Associations::Base
2013-05-21 17:03:07 -07:00
Santiago Pastorino
2b22acff53
Use the readers instead of accessing the ivar directly
2013-05-21 17:03:07 -07:00
Santiago Pastorino
251fdc7ba4
Rename opts to klass_options
2013-05-21 17:03:07 -07:00
Santiago Pastorino
0b9f69529f
Add default_embed_options
2013-05-21 17:03:07 -07:00
Santiago Pastorino
e273a2fb37
Use a third argument to pass serializer_options
2013-05-21 17:03:07 -07:00
Santiago Pastorino
c04d452823
Associations doesn't depend on the source serializer anymore :)
2013-05-21 17:03:07 -07:00
Santiago Pastorino
c1e710aae1
Save result of calling associated_object in a local var
2013-05-21 17:03:06 -07:00
Santiago Pastorino
baa690a01a
Move if object to the top
2013-05-21 17:03:06 -07:00
Santiago Pastorino
0917148617
serialize_ids doesn't use source serializer and it's object
2013-05-21 17:03:06 -07:00
Santiago Pastorino
9f5e872621
Extract id_key to a method
2013-05-21 17:03:06 -07:00
Santiago Pastorino
a41de0286f
Passing options[:hash] is not public API of include!
2013-05-21 17:03:06 -07:00
Santiago Pastorino
ea3566955c
Remove option method just use the reader
2013-05-21 17:03:06 -07:00
Santiago Pastorino
5017fb686a
Associations doesn't depend on source serializer anymore
2013-05-21 17:03:06 -07:00
Santiago Pastorino
460a250984
Get rid of refine
2013-05-21 17:03:06 -07:00
Santiago Pastorino
1a8709d71c
Move caching to a new module
2013-05-21 17:03:06 -07:00
Santiago Pastorino
f179a27ed7
Add docs to serializable
2013-05-21 17:03:06 -07:00
Santiago Pastorino
aaa08c25ef
Make include_meta and meta_key private
2013-05-21 17:03:06 -07:00
Santiago Pastorino
76fead041f
Make Serializer reuse Serializable
2013-05-21 17:03:06 -07:00
Santiago Pastorino
0e876624ec
Move reusable code to a module
2013-05-21 17:03:05 -07:00
Santiago Pastorino
64ed05c484
Define serializer as DefaultSerializer if not set
2013-05-21 17:03:05 -07:00
Steve Klabnik
fe84e0ad52
version bump 0.8.1
2013-05-05 17:35:51 -07:00
Sam
597a2e3148
allow serializers to implement an options attribute
2013-05-06 10:30:46 +10:00
Steve Klabnik
a022d464f5
Bump to 0.8.0
2013-05-05 13:45:50 -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
e8ae3e1bb3
allow singular embed when serializing association
...
Having
```ruby
has_one :post, embed: :ids
```
looks especially weird as it's a one-to-one association, hence there is
only one id. The following looks better:
```ruby
has_one :post, embed: :id
```
2013-05-05 11:02:42 +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
Wojciech Wnętrzak
82f50ef81f
Unify way of calling include_attribute? in attibutes and association methods.
2013-04-20 23:28:33 +02:00
Jason Kriss
4e762ee8b5
fix a couple typos
2013-04-18 13:39:14 -07: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
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
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
Prathamesh Sonpatki
7d1ce9c56e
Fixed typos
2013-03-26 18:18:20 +05:30
Kevin Mahoney
2bd447d69d
Pass options through when using default serializer
2013-03-22 13:12:33 +00:00
Steve Klabnik
680e2efbec
Merge pull request #246 from beerlington/dry-option-setup
...
Refactor and consolidate serializer option setup
2013-03-20 08:56:54 -07: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
Sam
af13d48dfa
improved caching of root node for better performance
2013-03-18 16:21:34 -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
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
c3966fe741
ArraySerializer is also cached
2013-03-14 22:54:05 +01: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
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
5a55a6831a
Remove line break on the conditional statement.
2013-03-06 11:48:50 -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
fabdc621ff
bumping to 0.7.0
2013-03-05 17:07:16 -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
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
Tony Pitale
dcd4121322
reduce 2x map; fixes datamapper eager loading
2013-02-17 16:44:27 -05: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
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
Steve Klabnik
7f87c9b3f2
Merge pull request #169 from dgeb/embed-with-id-suffix
...
Update foreign key naming conventions - fixes #158
2012-12-21 22:49:06 -08:00
Nick Ragaz
be005c6964
use _ids method instead of pluck
2012-12-21 17:35:16 -05:00