Skip to content

Commit

Permalink
Merge pull request #1535 from bf4/domitian-move-namespace-of-adapter-…
Browse files Browse the repository at this point in the history
…to-active-model-serializers

Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
  • Loading branch information
Yohan Robert committed Feb 28, 2016
2 parents 3975e36 + fcdb58f commit 8a04005
Show file tree
Hide file tree
Showing 67 changed files with 2,958 additions and 3,040 deletions.
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ Style/TrailingBlankLines:
- 'test/adapter/null_test.rb'
- 'test/serializers/cache_test.rb'
- 'test/serializers/fieldset_test.rb'
- 'test/support/stream_capture.rb'

# Offense count: 5
# Cop supports --auto-correct.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/v0.10.0.rc4)
- [Guides](docs)
- [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-9-stable)
- [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-8-stable)

## About

Expand Down
26 changes: 13 additions & 13 deletions docs/general/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It should be set only once, preferably at initialization.
For example:

```ruby
ActiveModelSerializers.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
```

or
Expand Down Expand Up @@ -117,46 +117,46 @@ The default adapter can be configured, as above, to use any class given to it.

An adapter may also be specified, e.g. when rendering, as a class or as a symbol.
If a symbol, then the adapter must be, e.g. `:great_example`,
`ActiveModel::Serializer::Adapter::GreatExample`, or registered.
`ActiveModelSerializers::Adapter::GreatExample`, or registered.

There are two ways to register an adapter:

1) The simplest, is to subclass `ActiveModel::Serializer::Adapter::Base`, e.g. the below will
1) The simplest, is to subclass `ActiveModelSerializers::Adapter::Base`, e.g. the below will
register the `Example::UsefulAdapter` as `"example/useful_adapter"`.

```ruby
module Example
class UsefulAdapter < ActiveModel::Serializer::Adapter::Base
class UsefulAdapter < ActiveModelSerializers::Adapter::Base
end
end
```

You'll notice that the name it registers is the underscored namespace and class.

Under the covers, when the `ActiveModel::Serializer::Adapter::Base` is subclassed, it registers
Under the covers, when the `ActiveModelSerializers::Adapter::Base` is subclassed, it registers
the subclass as `register("example/useful_adapter", Example::UsefulAdapter)`

2) Any class can be registered as an adapter by calling `register` directly on the
`ActiveModel::Serializer::Adapter` class. e.g., the below registers `MyAdapter` as
`ActiveModelSerializers::Adapter` class. e.g., the below registers `MyAdapter` as
`:special_adapter`.

```ruby
class MyAdapter; end
ActiveModel::Serializer::Adapter.register(:special_adapter, MyAdapter)
ActiveModelSerializers::Adapter.register(:special_adapter, MyAdapter)
```

### Looking up an adapter

| Method | Return value |
| :------------ |:---------------|
| `ActiveModel::Serializer::Adapter.adapter_map` | A Hash of all known adapters `{ adapter_name => adapter_class }` |
| `ActiveModel::Serializer::Adapter.adapters` | A (sorted) Array of all known `adapter_names` |
| `ActiveModel::Serializer::Adapter.lookup(name_or_klass)` | The `adapter_class`, else raises an `ActiveModel::Serializer::Adapter::UnknownAdapter` error |
| `ActiveModel::Serializer::Adapter.adapter_class(adapter)` | Delegates to `ActiveModel::Serializer::Adapter.lookup(adapter)` |
| `ActiveModel::Serializer.adapter` | A convenience method for `ActiveModel::Serializer::Adapter.lookup(config.adapter)` |
| `ActiveModelSerializers::Adapter.adapter_map` | A Hash of all known adapters `{ adapter_name => adapter_class }` |
| `ActiveModelSerializers::Adapter.adapters` | A (sorted) Array of all known `adapter_names` |
| `ActiveModelSerializers::Adapter.lookup(name_or_klass)` | The `adapter_class`, else raises an `ActiveModelSerializers::Adapter::UnknownAdapter` error |
| `ActiveModelSerializers::Adapter.adapter_class(adapter)` | Delegates to `ActiveModelSerializers::Adapter.lookup(adapter)` |
| `ActiveModelSerializers::Adapter.configured_adapter` | A convenience method for `ActiveModelSerializers::Adapter.lookup(config.adapter)` |

The registered adapter name is always a String, but may be looked up as a Symbol or String.
Helpfully, the Symbol or String is underscored, so that `get(:my_adapter)` and `get("MyAdapter")`
may both be used.

For more information, see [the Adapter class on GitHub](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/adapter.rb)
For more information, see [the Adapter class on GitHub](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/adapter.rb)
2 changes: 1 addition & 1 deletion docs/general/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Payload (example):
```ruby
{
serializer: PostSerializer,
adapter: ActiveModel::Serializer::Adapter::Attributes
adapter: ActiveModelSerializers::Adapter::Attributes
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/rfcs/0000-namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ at the first moment.
## Renaming of class and modules

When moving some content to the new namespace we can find some names that does
not make much sense like `ActiveModelSerializers::Serializer::Adapter::JsonApi`.
not make much sense like `ActiveModel::Serializer::Adapter::JsonApi`.
Discussion of renaming existing classes / modules and JsonApi objects will
happen in separate pull requests, and issues, and in the google doc
https://docs.google.com/document/d/1rcrJr0sVcazY2Opd_6Kmv1iIwuHbI84s1P_NzFn-05c/edit?usp=sharing
Expand Down
3 changes: 2 additions & 1 deletion lib/active_model/serializable_resource.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'set'
require 'active_model_serializers/adapter'
module ActiveModel
class SerializableResource
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links])
Expand Down Expand Up @@ -30,7 +31,7 @@ def serialization_scope_name=(scope_name)
end

def adapter
@adapter ||= ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)
@adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
end
alias_method :adapter_instance, :adapter

Expand Down
7 changes: 4 additions & 3 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Serializer
include Links
include Meta
include Type
require 'active_model/serializer/adapter'

# @param resource [ActiveRecord::Base, ActiveModelSerializers::Model]
# @return [ActiveModel::Serializer]
Expand All @@ -42,9 +41,11 @@ def self.serializer_for(resource, options = {})
end
end

# @see ActiveModel::Serializer::Adapter.lookup
# @see ActiveModelSerializers::Adapter.lookup
# Deprecated
def self.adapter
ActiveModel::Serializer::Adapter.lookup(config.adapter)
warn 'Calling adapter method in Serializer, please use the ActiveModelSerializers::configured_adapter'
ActiveModelSerializers::Adapter.lookup(config.adapter)
end

# @api private
Expand Down
91 changes: 0 additions & 91 deletions lib/active_model/serializer/adapter.rb

This file was deleted.

100 changes: 0 additions & 100 deletions lib/active_model/serializer/adapter/attributes.rb

This file was deleted.

58 changes: 0 additions & 58 deletions lib/active_model/serializer/adapter/base.rb

This file was deleted.

Loading

0 comments on commit 8a04005

Please sign in to comment.