Benjamin Fleischer
1d8a3d039a
Enforce case requires else; allow else nil
2015-09-21 09:50:53 -05:00
L. Preston Sego III
a74ea189cd
Refactors of the Attribute adapter. Adds support for nested associations specified from the include key in the controller. Adds some tests and some method documentation
2015-09-21 10:35:47 -04:00
L. Preston Sego III
8f2dd66710
Merge pull request #1183 from rails-api/block_style
...
Update Rubocop todo
2015-09-21 01:25:50 -05:00
Lucas Hosseini
4976837c31
Fix options passing in Json and Attributes adapters.
2015-09-21 07:13:17 +02:00
Benjamin Fleischer
140b4f2735
Update Rubocop todo
2015-09-21 00:11:08 -05:00
Benjamin Fleischer
ca6b193fcb
Enforce Rails-style (line-count-based) block style
2015-09-21 00:00:53 -05:00
Lucas Hosseini
ac06013aeb
Add support for wildcard includes + improve perfs on JsonApi includes.
2015-09-21 05:58:00 +02:00
Benjamin Fleischer
19de5f7722
Introduce Adapter::Base
...
Breaking change:
- Adapters now inherit Adapter::Base
- 'Adapter' is now a module, no longer a class
Why?
- using a class as a namespace that you also inherit from is complicated and circular at time i.e.
buggy (see https://github.com/rails-api/active_model_serializers/pull/1177 )
- The class methods on Adapter aren't necessarily related to the instance methods, they're more
Adapter functions
- named `Base` because it's a Rails-ism
- It helps to isolate and highlight what the Adapter interface actually is
2015-09-20 12:26:04 -05:00
Benjamin Fleischer
ad2ca3b45c
Remove Adapter autoloads in favor of require
...
Adapters must be eager loaded to ensure they are defined
before they are used as namespacing.
cf6a074a1c (diff-41f2b3509d33e1c65bb70ee0ec7a2eea)
2015-09-18 12:44:53 -05:00
Benjamin Fleischer
c6f8d0f5f2
Rename FlattenJson to Attributes (allow plural adapter names)
2015-09-18 10:17:02 -05:00
Benjamin Fleischer
ceef214f1e
FlattenJson adapter no longer inherits Json adapter
2015-09-18 10:15:49 -05:00
L. Preston Sego III
24a5f3843e
Merge pull request #1171 from shicholas/require_statements
...
add require statements to top of file
2015-09-18 02:27:23 -04:00
L. Preston Sego III
701eb17a27
Merge pull request #1172 from bf4/better_adapter_registration
...
Better serializer registration, get more than just the first module
2015-09-18 02:12:54 -04:00
L. Preston Sego III
e0a0ad3e46
Merge pull request #1167 from rails-api/simplify_serializer_attributes
...
Delegate Serializer.attributes to Serializer.attribute
2015-09-18 01:24:45 -04:00
Nicholas Shook
7f17ec8afa
bring back autoload - fix test
2015-09-17 22:03:22 -07:00
Benjamin Fleischer
eb1264ad99
Better serializer registration, get more than just the first module
...
But is potentially breaking anyone on rc3, but the fix is just
to manually register the adapter with the rc3-style name
2015-09-17 23:33:04 -05:00
Benjamin Fleischer
484426ce17
Delegate Serializer.attributes to Serializer.attribute
2015-09-17 22:11:57 -05:00
Nicholas Shook
444b4cd1d8
all require
2015-09-17 14:06:55 -07:00
Nicholas Shook
faa56482d1
full require
2015-09-17 14:06:55 -07:00
Nicholas Shook
6bdb4a13e2
removed autoload statements
2015-09-17 14:06:54 -07:00
Nicholas Shook
a9e3143c19
add require statements to top of file
...
Based on
https://github.com/rails-api/active_model_serializers/issues/1170#issuecomment-141184047
2015-09-17 14:06:54 -07:00
Benjamin Fleischer
0091be89f8
Consistently refer to the 'JSON API' and the 'JsonApi' adapter
2015-09-17 15:22:28 -05:00
Benjamin Fleischer
c9ae868bfb
Comment private accessor warnings
2015-09-17 14:32:22 -05:00
Benjamin Fleischer
9d65f0adc5
Distinguish options ivar from local; Extract latent Adapter::CachedSerializer
2015-09-17 10:45:09 -05:00
João M. D. Moura
1ca73e0c33
updating version to new release
2015-09-16 12:19:44 -03:00
L. Preston Sego III
610775a95f
Merge pull request #1129 from bf4/remove_serializable_resource_serialize
...
Remove SerializableResource.serialize in favor of `.new`
2015-09-15 17:32:44 -04:00
L. Preston Sego III
a34cb998c7
rubocop-fixes
2015-09-15 14:58:04 -04:00
L. Preston Sego III
1bff6173d1
Merge pull request #1089 from bf4/add_logger
...
Add ActiveModelSerializers.logger with default null device
2015-09-15 14:51:29 -04:00
João Moura
479146c02a
Merge pull request #1121 from beauby/fix-jsonapi-links
...
Refactor `add_links` in JSONAPI adapter.
2015-09-15 05:00:39 -03:00
Lucas Hosseini
fb7ec88e2e
Remove unnecessary parentheses accidentally reintroduced in #1017 .
2015-09-15 00:25:37 +02:00
Lucas Hosseini
319a9071af
Remove legacy method accidentally reintroduced in #1017 .
2015-09-15 00:22:28 +02:00
Lucas Hosseini
285cdf841e
Split serializable_hash into two methods.
2015-09-14 06:46:52 +02:00
Lucas Hosseini
572ff7db20
Refactor add_links in JSONAPI adapter.
2015-09-14 06:46:52 +02:00
Lucas Hosseini
2789a579e8
Merge pull request #1131 from beauby/jsonapi-include-tree
...
Extended format for JSONAPI `include` option
2015-09-13 23:10:05 +02:00
Lucas Hosseini
ce7a839f3d
Extended format for JSONAPI include option.
2015-09-13 22:45:47 +02:00
Ville Lautanala
fada4dcb08
Fix typo in fieldset exception
2015-09-12 18:56:15 +03:00
L. Preston Sego III
b594d1487b
Merge pull request #1132 from beauby/fix-flatten-json
...
Get rid of unnecessary instance variables, and implied dependencies.
2015-09-12 11:51:38 -04:00
Lucas Hosseini
a9d07cd68f
Get rid of unnecessary instance variables, and implied dependencies.
2015-09-10 04:02:06 +02:00
Benjamin Fleischer
28345adef0
Use Adapter.const_get instead of safe_constantize
...
(Thanks to sandstrom for the reference to ActiveJob::QueueAdapters
a11571cec3/activejob/lib/active_job/queue_adapters.rb (L123-L133)
2015-09-09 08:55:20 -05:00
Benjamin Fleischer
363345b8dd
Rename Adapter.get to Adapter.lookup
...
Per https://github.com/rails-api/active_model_serializers/pull/1017#discussion_r39003855
comment by sandstrom in discussion of the inherited hook
> I'm thinking that it would be better to register adapters manually, without using the hook, i.e.
> have people call ActiveModel::Serializer::Adapter.register directly (perhaps in an initializer).
> Possibly, some inspiration can be taken from how ActiveJob adapters are wired[1].
> [1] a11571cec3/activejob/lib/active_job/queue_adapter.rb (L52-L56)
2015-09-09 08:55:20 -05:00
Benjamin Fleischer
af99c0d9e6
Ensure inheritance hooks run
...
I was seeing transient failures where adapters may not be registered.
e.g. https://travis-ci.org/rails-api/active_model_serializers/builds/77735382
Since we're using the Adapter, JsonApi, and Json classes
as namespaces, some of the conventions we use for modules don't apply.
Basically, we don't want to define the class anywhere besides itself.
Otherwise, the inherited hooks may not run, and some adapters may not
be registered.
For example:
If we have a class Api `class Api; end`
And Api is also used as a namespace for `Api::Product`
And the classes are defined in different files.
In one file:
```ruby
class Api
autoload :Product
def self.inherited(subclass)
puts
p [:inherited, subclass.name]
puts
end
end
```
And in another:
```ruby
class Api
class Product < Api
def sell_sell_sell!
# TODO: sell
end
end
end
```
If we load the Api class file first, the inherited hook will be defined on the class
so that when we load the Api::Product class, we'll see the output:
```plain
[ :inherited, Api::Product]
```
However, if we load the Api::Product class first, since it defines the `Api` class
and then inherited from it, the Api file was never loaded, the hook never defined,
and thus never run.
By defining the class as `class Api::Product < Api` We ensure the the Api class
MUST be defined, and thus, the hook will be defined and run and so sunshine and unicorns.
Appendix:
The below would work, but triggers a circular reference warning.
It's also not recommended to mix require with autoload.
```ruby
require 'api'
class Api
class Product < Api
def sell_sell_sell!
# TODO: sell
end
end
end
```
This failure scenario was introduced by removing the circular reference warnings in
https://github.com/rails-api/active_model_serializers/pull/1067
Style note:
To make diffs on the adapters smalleer and easier to read, I've maintained the same
identention that was in the original file. I've decided to prefer ease of reading
the diff over style, esp. since we may later return to the preferred class declaration style.
with '#' will be ignored, and an empty message aborts the commit.
2015-09-09 08:55:20 -05:00
Benjamin Fleischer
7eddbe418d
Remove SerializableResource.serialize in favor of .new
...
Per discussion in https://github.com/rails-api/active_model_serializers/issues/1098
2015-09-08 23:28:10 -05:00
Benjamin Fleischer
d9e76c29d5
Make Adapters registerable so they are not namespace-constrained
...
Changes:
- Introduce Adapter::get for use by Serializer.adapter
- Move Adapter-finding logic from Adapter::adapter_class into Adapter::get
Introduced interfaces:
- non-inherited methods
```ruby
ActiveModel::Serializer::Adapter.adapter_map # a Hash<adapter_name, adapter_class>
ActiveModel::Serializer::Adapter.adapters # an Array<adapter_name>
ActiveModel::Serializer::Adapter.register(name, klass) # adds an adapter to the adapter_map
ActiveModel::Serializer::Adapter.get(name_or_klass) # raises Argument error when adapter not found
```
- Automatically register adapters when subclassing
```ruby
def self.inherited(subclass)
ActiveModel::Serializer::Adapter.register(subclass.to_s.demodulize, subclass)
end
```
- Preserves subclass method `::adapter_class(adapter)`
```ruby
def self.adapter_class(adapter)
ActiveModel::Serializer::Adapter.get(adapter)
end
```
- Serializer.adapter now uses `Adapter.get(config.adapter)` rather than have duplicate logic
2015-09-08 22:59:36 -05:00
Bruno Bacarini
8634503849
Remove url options
...
Removing url options because It does not works at all.
Thus, there are others PR at the moment to include url(links) as well.
2015-09-07 12:13:19 -03:00
Lucas Hosseini
f27f13ccc1
Fix style.
2015-09-06 19:29:51 +02:00
Lucas Hosseini
070a2e63bd
Merge remote-tracking branch 'upstream/master' into fix-jsonapi-ri
2015-09-06 17:21:43 +02:00
Benjamin Fleischer
228cc1c92a
Rubocop: Consistent spacing
2015-09-03 20:51:40 -05:00
Benjamin Fleischer
bdfe13c527
Style/StringLiterals single quote all the things
2015-09-03 20:50:45 -05:00
Benjamin Fleischer
09c97de90d
Add Style enforcer (via Rubocop)
...
It will fail the build, but as it is currently,
most of the cops are 'todos'. Great for new contributors.. :)
2015-09-03 20:50:45 -05:00
João Moura
6784866a2d
Merge pull request #1079 from bf4/all_serializer_have_object
...
Add ArraySerializer#object like Serializer
2015-09-03 01:43:14 -03:00
Lucas Hosseini
3793f3ff4b
Rename resource_objects_for to primary_data_for.
2015-09-02 19:27:40 +02:00
Lucas Hosseini
f8c553a0ed
Cleanup.
2015-09-02 15:58:31 +02:00
Lucas Hosseini
a8a0566d29
Refactor relationships_for.
2015-09-01 21:16:00 +02:00
Lucas Hosseini
c593adbcb2
Further cleanup add_included.
2015-09-01 20:46:18 +02:00
Lucas Hosseini
bae4951e05
Further cleanup included_for.
2015-09-01 20:30:38 +02:00
Lucas Hosseini
91c5cbe0b9
Cleanup add_included.
2015-09-01 17:57:30 +02:00
Lucas Hosseini
f7612f2542
Further refactor/streamline method names.
2015-09-01 16:52:43 +02:00
Lucas Hosseini
04012052a6
Fix 'id' -> :id.
2015-09-01 15:39:29 +02:00
João Moura
e0b74d8731
Merge pull request #1096 from beauby/fix-attribute
...
Fix definition of serializer attributes with multiple calls to `attri…
2015-09-01 09:42:59 -03:00
Lucas Hosseini
c4faafdebc
Refactor resource_identifier.
2015-09-01 10:15:50 +02:00
Lucas Hosseini
d9c680599a
Refactor.
2015-09-01 01:41:29 +02:00
Benjamin Fleischer
9673b6471c
Better lint
...
Extracted from
https://github.com/rails-api/active_model_serializers/pull/1004/files#diff-56455571c4ba7a2b4c640b9e8168f522R40
Correct cache_key lint for ActiveRecord 4.1+
https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/integration.rb
def cache_key
https://github.com/rails/rails/blob/4-1-stable/activerecord/lib/active_record/integration.rb
def cache_key(*timestamp_names)
2015-08-31 00:22:17 -05:00
João Moura
b20f1f5f9d
Merge pull request #1102 from beauby/remove-embed
...
Remove remains of `embed` option.
2015-08-31 01:33:30 -03:00
Benjamin Fleischer
005f71e2c2
Add ActiveModelSerializers.logger with default null device
2015-08-30 23:26:31 -05:00
Lucas Hosseini
343f8b96bd
Fix bug preventing id overriding.
2015-08-31 06:25:20 +02:00
João Moura
9ff35dabda
Merge pull request #1090 from bf4/clarify_ams_dependencies
...
Clarify AMS dependencies
2015-08-31 00:39:24 -03:00
Benjamin Fleischer
e3d3d92201
Clarify AMS dependencies
2015-08-30 22:26:25 -05:00
Lucas Hosseini
f95f7369f0
Refactor add_resource_relationship.
2015-08-31 03:24:03 +02:00
Lucas Hosseini
8482abfac7
Move id and json_api_type methods from Serializer to JsonApi.
2015-08-31 02:32:38 +02:00
Lucas Hosseini
c5446d759f
Remove traces of embed option.
2015-08-31 01:26:22 +02:00
Lucas Hosseini
995bbcc18d
Fix definition of serializer attributes with multiple calls to attribute instead of one single call to attributes.
2015-08-28 21:06:10 +02:00
João Moura
64168cbecd
Merge pull request #1081 from beauby/jsonapi-singular-plural-config
...
Add configuration option to set resource type to singular/plural
2015-08-28 07:47:55 -03:00
Benjamin Fleischer
d315151e8a
Fix warnings
...
JRuby-specific: fix 'warning: (...) interpreted as grouped expression'
2015-08-26 09:22:02 -05:00
João Moura
af280abbb7
Merge pull request #1066 from rails-api/appveyor
...
Adding appveyor to the project
2015-08-26 04:46:16 -03:00
Lucas Hosseini
91235ba7bc
Add configuration option to set resource type to singular/plural with jsonapi.
2015-08-24 22:55:22 +02:00
Benjamin Fleischer
dc4ee94fea
Add ArraySerializer#object like Serializer
2015-08-24 13:51:46 -05:00
João Moura
87c47f8fdc
Merge pull request #1041 from bacarini/master
...
Adding pagination links
2015-08-22 13:38:32 -03:00
João Moura
fc7b9c3c14
Merge pull request #1063 from bf4/poro_lint
...
Lead by example: lint PORO model
2015-08-20 03:53:11 -03:00
Bruno Bacarini
3c3578a9b8
improvements on how to get self link on pagination class
2015-08-19 11:16:53 -03:00
Bruno Bacarini
01eab3bdb4
send whole request context to model serializer
2015-08-19 10:48:48 -03:00
Bruno Bacarini
2c2f948fa0
Add pagination links automatically
...
Pagination links will be included in your response automatically as long
as the resource is paginated using Kaminari or WillPaginate
and if you are using a JSON-API adapter. The others adapters does not have this feature.
2015-08-18 19:04:04 -03:00
Bruno Bacarini
a41d90cce4
add self to pagination links
2015-08-18 19:04:04 -03:00
Bruno Bacarini
59ae84baba
exchange to a faster regex to get origina_url
2015-08-18 19:04:03 -03:00
Bruno Bacarini
77a8f66ad8
fix message on raise of pagination links class
2015-08-18 19:04:03 -03:00
Bruno Bacarini
e0d050d2af
remove resource and options attr_reader from array_serialize
2015-08-18 19:04:03 -03:00
Bruno Bacarini
7be25fef14
include query_parameters on pagination links as well
2015-08-18 19:04:03 -03:00
Bruno Bacarini
e62a7d6f34
return complete URIs on pagination links
2015-08-18 19:04:03 -03:00
Bruno Bacarini
1fe8b06986
exchange pagination class to inside json_api scope
2015-08-18 19:04:02 -03:00
Bruno Bacarini
b864302695
remove 'page object' on paginations links'
2015-08-18 19:04:02 -03:00
Bruno Bacarini
f7c77c1256
add feature to include pagination links in response
2015-08-18 19:04:02 -03:00
Benjamin Fleischer
215fb85c7f
Test caller line parsing and digesting
2015-08-18 17:32:29 -04:00
João Moura
e384b65f5d
Merge pull request #1048 from bf4/cleanup_meta_in_adapter
...
Let FlattenJson adapter decide it doesn't include meta
2015-08-18 16:23:03 -03:00
Benjamin Fleischer
98d009a000
Let FlattenJson adapter decide it doesn't include meta
2015-08-18 15:13:21 -04:00
Benjamin Fleischer
dca286b0ec
Lead by example: lint PORO model
2015-08-18 12:59:12 -04:00
Eric Guo
f93a7e8b41
need lookahead match for windows file path contain 'c:/git/'
...
So we will got full file path instead of only c if caller.first is: c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'
CALLER_FILE = /
/A # start of string
\S+ # one or more non-spaces
(?= # stop previous match when
:\d+:in # a colon is followed by one or more digits
# followed by a colon followed by in
)
/x
credit from https://gist.github.com/mikezter/540132 and @bf4
2015-08-18 09:52:34 +08:00
Aaron Lerch
35c8f0d835
Update fragment cache to support namespaced objects
2015-08-17 17:12:30 -04:00
Mikhail Topolskiy
e8e4bdefd2
Use underscored json_root
2015-08-13 20:31:48 +03:00
João Moura
b4949fbc2a
Merge pull request #1049 from bf4/fix_json_api_adapter_serialable_hash
...
Fix incorrect s/options = {}/options ||= {}
2015-08-12 11:08:39 -03:00
Benjamin Fleischer
43e09c03de
Fix incorrect s/options = {}/options ||= {}
...
Introduced in #965 , surfaced in #1041
2015-08-11 17:08:09 -05:00
Josh Lane
033ce8e88d
allow for a type attribute
...
* "namespace" json_api specific type method
2015-08-11 08:33:05 -07:00