Skip to content

Commit 252f9c4

Browse files
domitianbf4
authored andcommitted
Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer Changed namespace of adapters in serializers and other folders Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file Require ActiveSupport's string/inflections We depend on string/inflections to define String#underscore. Refactor JsonApi adapter to avoid redundant computations. Update readme.md to link to v0.10.0.rc4 changed namespace of adapter folder testcases Changed all namespaces of adapter under active_moder_serializers Namespaced IncludeTree which is from serializer module, so needed to namespace it properly Fixed wrong namsepacing of fieldset namespace change in deserializer json_api Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously Modified logging test and adapter test cases to make the testcases pass Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc Rubocop errors are fixed by underscore naming unused variables Moved the require of adapter to serializable resource Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method Fixed frament cache test which is calling Serializer.adapter Changed the name of lookup_adapter_from_config to configured_adapter Changed the docs which will show the new namespace of adapters Rubocop fix
1 parent f5ec8ed commit 252f9c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2645
-2716
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Breaking changes:
44
Features:
55
Fixes:
6+
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
67
Misc:
78

89
### v0.10.0.rc4 (2016/01/27 11:00 +00:00)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
## Documentation
99

1010
- [0.10 (master) Documentation](https://github.com/rails-api/active_model_serializers/tree/master)
11-
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers)
11+
- [![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)
1212
- [Guides](docs)
1313
- [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
14+
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-9-stable)
1415
- [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
16+
- [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/0-8-stable)
1517

1618
## About
1719

docs/general/adapters.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It should be set only once, preferably at initialization.
1111
For example:
1212

1313
```ruby
14-
ActiveModelSerializers.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
14+
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
1515
```
1616

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

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

122122
There are two ways to register an adapter:
123123

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

127127
```ruby
128128
module Example
129-
class UsefulAdapter < ActiveModel::Serializer::Adapter::Base
129+
class UsefulAdapter < ActiveModelSerializers::Adapter::Base
130130
end
131131
end
132132
```
133133

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

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

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

143143
```ruby
144144
class MyAdapter; end
145-
ActiveModel::Serializer::Adapter.register(:special_adapter, MyAdapter)
145+
ActiveModelSerializers::Adapter.register(:special_adapter, MyAdapter)
146146
```
147147

148148
### Looking up an adapter
149149

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

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

162-
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)
162+
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)

docs/general/instrumentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Payload (example):
1717
```ruby
1818
{
1919
serializer: PostSerializer,
20-
adapter: ActiveModel::Serializer::Adapter::Attributes
20+
adapter: ActiveModelSerializers::Adapter::Attributes
2121
}
2222
```
2323

docs/rfcs/0000-namespace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ at the first moment.
7070
## Renaming of class and modules
7171

7272
When moving some content to the new namespace we can find some names that does
73-
not make much sense like `ActiveModelSerializers::Serializer::Adapter::JsonApi`.
73+
not make much sense like `ActiveModelSerializers::Adapter::JsonApi`.
7474
Discussion of renaming existing classes / modules and JsonApi objects will
7575
happen in separate pull requests, and issues, and in the google doc
7676
https://docs.google.com/document/d/1rcrJr0sVcazY2Opd_6Kmv1iIwuHbI84s1P_NzFn-05c/edit?usp=sharing

lib/active_model/serializable_resource.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'set'
2+
require 'active_model_serializers/adapter'
23
module ActiveModel
34
class SerializableResource
45
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links])
@@ -30,7 +31,7 @@ def serialization_scope_name=(scope_name)
3031
end
3132

3233
def adapter
33-
@adapter ||= ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)
34+
@adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
3435
end
3536
alias_method :adapter_instance, :adapter
3637

lib/active_model/serializer.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Serializer
2121
include Caching
2222
include Links
2323
include Type
24-
require 'active_model/serializer/adapter'
24+
# Deprecated
25+
require 'active_model_serializers/adapter'
2526

2627
# @param resource [ActiveRecord::Base, ActiveModelSerializers::Model]
2728
# @return [ActiveModel::Serializer]
@@ -40,9 +41,11 @@ def self.serializer_for(resource, options = {})
4041
end
4142
end
4243

43-
# @see ActiveModel::Serializer::Adapter.lookup
44+
# @see ActiveModelSerializers::Adapter.lookup
45+
# Deprecated
4446
def self.adapter
45-
ActiveModel::Serializer::Adapter.lookup(config.adapter)
47+
warn 'Calling adapter method in Serializer, please use the ActiveModelSerializers::configured_adapter'
48+
ActiveModelSerializers::Adapter.lookup(config.adapter)
4649
end
4750

4851
# @api private

lib/active_model/serializer/adapter.rb

Lines changed: 0 additions & 91 deletions
This file was deleted.

lib/active_model/serializer/adapter/attributes.rb

Lines changed: 0 additions & 66 deletions
This file was deleted.

lib/active_model/serializer/adapter/base.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)