Santiago Pastorino
2b70503896
Add ActiveModel::SerializerSupport
2013-10-24 16:09:00 -02:00
Santiago Pastorino
cef6f85f44
Deprecate include in favor of side_load
2013-10-24 15:09:26 -02:00
Santiago Pastorino
48db253765
embed_in_root is now side_load
2013-10-24 14:57:41 -02:00
Santiago Pastorino
5c6541145a
Allow to embed nothing but still side loading
...
Closes #361 , #399 , #401
2013-10-24 13:24:49 -02:00
Santiago Pastorino
df5ef33ae6
Allow to turn off ams
...
Closes #378
You can define now
```
def default_serializer_options
{ serializer: false }
end
```
2013-10-23 20:34:34 -02:00
Łukasz Strzałkowski
d46584af40
Wrap config's data hash in mutex
2013-10-21 20:27:01 +00:00
Arthur Neves
05ec509e1c
Use ActiveSupport::Deprecation.warn instead of warn
2013-10-21 15:02:39 -04:00
Santiago Pastorino
7dcef9f0f5
Rename Settings to Config and use accessors to configure things
2013-10-21 16:23:35 -02:00
Arthur Neves
84801301b9
Add deprecation message to .embed method
2013-10-21 13:08:07 -04:00
Arthur Neves
41f1855056
Add accessors to settings class
2013-10-21 13:05:39 -04:00
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
8462a73f3a
Make render json work when not using AMS
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
29148cbe1c
Add AC::Serialization#serialization_scope as a class level method
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
af357619c1
Add AMS support to AR objects
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0d3b56e9cf
Implement AC integration
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
31e1dab69f
require rails >= 3.2
...
* remove ancient confusing comment in SerializerGenerator
2013-05-30 15:26:17 -06:00
Tee Parham
74ba9dc76c
upgrade hash syntax
2013-05-30 15:25:06 -06:00
Tee Parham
143e5d9866
do not generate id method (was for 1.8 only)
...
see https://github.com/rails-api/active_model_serializers/issues/127
for original motivation
2013-05-29 19:39:00 -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
Steve Klabnik
da779c259f
Merge pull request #293 from goshakkk/mongoid-support
...
add support of mongoid collection serialization
2013-05-05 12:00:04 -07:00
Gosha Arinich
1482081766
add support of mongoid collection serialization
2013-05-05 21:50:34 +03: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
Gosha Arinich
7f75b15ddd
include serializer support into mongoid
2013-05-04 22:43:11 +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
Steve Klabnik
3433eca4d3
Merge pull request #268 from vanstee/escape-attribute-names
...
Support "unsymbolizable" strings as attribute names
2013-04-15 17:25:24 -07:00
Jakub Arnold
1c1a4f7673
Fix serialization_scope to check for private/protected methods
...
The semantics of respond_to? on Ruby 2.0 have changed to return false for protected methods, which is usually the case for helpers like current_user.
2013-04-13 09:59:10 +03: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
2edaa22605
Require _our_ resource_override.
...
Basically, when anyone else made a 'resource_override' generator,
it'd only require once. Because that's how require works. So let's make
sure that we require ours and nobody else's.
Fixes #251 .
2013-04-03 23:24:19 -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
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
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
Steve Klabnik
145b6d499d
First part of a fix for #208 .
...
I would like to get this under test.
2013-03-19 13:52:20 -07: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
5027f04441
Update railtie
2013-03-14 22:40:07 +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