Commit Graph

527 Commits

Author SHA1 Message Date
Benjamin Fleischer
484426ce17 Delegate Serializer.attributes to Serializer.attribute 2015-09-17 22:11:57 -05:00
L. Preston Sego III
ee40e9fcef Merge pull request #1173 from bf4/comment_private_reader_warnings
Comment private accessor warnings
2015-09-17 15:35:45 -04:00
Benjamin Fleischer
c9ae868bfb Comment private accessor warnings 2015-09-17 14:32:22 -05:00
L. Preston Sego III
61c54bddcd Merge pull request #1166 from rails-api/clarify_options_variable
Prefer methods over instance variables
2015-09-17 15:14:01 -04:00
Benjamin Fleischer
9d65f0adc5 Distinguish options ivar from local; Extract latent Adapter::CachedSerializer 2015-09-17 10:45:09 -05:00
Benjamin Fleischer
3f0794bd39 Merge pull request #1168 from bf4/fix_appveyor
Fix appveyor failure cache not being expired
2015-09-17 10:05:40 -05:00
Benjamin Fleischer
c43e8e2a32 Fix or skip appveyor failure on cache expiration 2015-09-17 09:30:29 -05:00
L. Preston Sego III
a60e1ea82e Merge pull request #1161 from bf4/remove_duplicate_test_helper
Remove duplicate test helper
2015-09-17 07:46:57 -04:00
João Moura
47a846d2d5 Fixing the travis build svg to amster 2015-09-16 12:40:53 -03:00
João M. D. Moura
1ca73e0c33 updating version to new release 2015-09-16 12:19:44 -03:00
Benjamin Fleischer
26277ea1f9 Remove duplicate test helper 2015-09-16 08:54:33 -05: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
2111ae8ec4 Merge pull request #1155 from CodedBeardedSignedTaylor/documentation
Outside controller use tutorial
2015-09-15 17:08:20 -04:00
Terminator3
173f21d942 outside controller use tutorial 2015-09-15 15:55:35 -05:00
João Moura
0c42e32499 Merge pull request #1154 from NullVoxPopuli/rubocop-fixes
Rubocop fixes for issues introduced by #1089
2015-09-15 15:59:38 -03: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
L. Preston Sego III
a453de112b Merge pull request #1109 from bf4/fix_minitest_after_run
Make better use of Minitest's lifecycle
2015-09-15 14:18:07 -04:00
L. Preston Sego III
736591c472 Merge pull request #1144 from bacarini/master
Fix Markdown to adapters documentation
2015-09-15 14:17:33 -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
L. Preston Sego III
d7534a669c Merge pull request #1150 from beauby/fix-jsonapi-add-relationships
Remove legacy method accidentally reintroduced in #1017
2015-09-14 19:21:11 -04: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
L. Preston Sego III
1ac82a1a04 Merge pull request #1149 from mattmueller/update-docs-for-nested-includes
Update README with nested included association example.
2015-09-14 13:57:08 -04:00
Matt Mueller
6395f69541 Update README with nested included association example. 2015-09-14 13:35:29 -04: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
Bruno Bacarini
9aa237adc2 Fix Markdown to adapters documentation 2015-09-13 21:16:50 -03:00
Lucas Hosseini
7e2f3d122b Merge pull request #1110 from beauby/add-ar-models-tests
Add lint tests for AR models
2015-09-14 02:05:54 +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
L. Preston Sego III
ee55af6df5 Merge pull request #1142 from leighhalliday/master
Updating wording on cache expiry in README
2015-09-13 06:38:17 -04:00
Leigh Halliday
4440a092d2 Updating wording on cache expiry in README 2015-09-12 20:17:44 -04:00
L. Preston Sego III
258f116c3c Merge pull request #1140 from lautis/fieldset-exception-typo
Fix typo in fieldset exception
2015-09-12 12:30:13 -04: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
L. Preston Sego III
885d61120f Fixed indentation in readme under 'using without render' 2015-09-12 11:36:51 -04:00
L. Preston Sego III
b9b94f00ff Merge pull request #1139 from PericlesTheo/serializer_without_render_doc
Documentation for serializing resources without render
2015-09-12 10:46:55 -04:00
Pericles Theodorou
a93ddda83e Documentation for serializing resources without render 2015-09-12 15:29:03 +01:00
João Moura
4399c1ad1a Merge pull request #1017 from bf4/registerable_adapters
Make Adapters registerable so they are not namespace-constrained
2015-09-11 02:24:37 -03:00
Lucas Hosseini
a9d07cd68f Get rid of unnecessary instance variables, and implied dependencies. 2015-09-10 04:02:06 +02:00
Benjamin Fleischer
880f235f0f Lower minimum coverage, minimal changes in this PR 2015-09-09 08:55:20 -05: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
Lucas Hosseini
ec6260870d Add lint tests for AR models. 2015-09-07 18:34:42 +02:00
João Moura
1388ae82f2 Merge pull request #1120 from Eric-Guo/master
Add windows platform to loading sqlite3
2015-09-07 13:10:03 -03:00
João Moura
f4b17166eb Merge pull request #1123 from bacarini/master
Remove url options
2015-09-07 13:05:04 -03:00