Skip to content

Commit

Permalink
Follow up to #1535
Browse files Browse the repository at this point in the history
- The removed classes and modules were added back with deprecation
  warning and deprecation test were added for them.
- One test was renamed because it contained `__`.
- Some tests were refactored.
- The ActiveModelSerializers::Deserialization module is now called
  Adapter instead of ActiveModelSerializers::Adapter.
- The changelog was added for #1535
  • Loading branch information
Yohan Robert authored and bf4 committed Mar 7, 2016
1 parent 79e6acb commit dd94fe2
Show file tree
Hide file tree
Showing 24 changed files with 823 additions and 614 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Fixes:
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)

Misc:
- [#1543](https://github.com/rails-api/active_model_serializers/pull/1543) Add the changes missing from #1535. (@groyoh)
- [#1535](https://github.com/rails-api/active_model_serializers/pull/1535) Move the adapter and adapter folder to
active_model_serializers folder and changes the module namespace. (@domitian @bf4)
- [#1497](https://github.com/rails-api/active_model_serializers/pull/1497) Add JRuby-9000 to appveyor.yml(@corainchicago)

### v0.10.0.rc4 (2016/01/27 11:00 +00:00)
Expand Down
4 changes: 3 additions & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
# reified when subclassed to decorate a resource.
module ActiveModel
class Serializer
extend ActiveSupport::Autoload
include Configuration
include Associations
include Attributes
include Caching
include Links
include Meta
include Type
autoload :Adapter

# @param resource [ActiveRecord::Base, ActiveModelSerializers::Model]
# @return [ActiveModel::Serializer]
Expand All @@ -46,7 +48,7 @@ def self.serializer_for(resource, options = {})
# @see ActiveModelSerializers::Adapter.lookup
# Deprecated
def self.adapter
warn 'Calling adapter method in Serializer, please use the ActiveModelSerializers::configured_adapter'
warn 'Calling adapter method in Serializer, please use the ActiveModelSerializers::Adapter.configured_adapter'
ActiveModelSerializers::Adapter.lookup(config.adapter)
end

Expand Down
49 changes: 49 additions & 0 deletions lib/active_model/serializer/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module ActiveModel
class Serializer
# @deprecated Use ActiveModelSerializers::Adapter instead
module Adapter
class << self
def create(resource, options = {})
warn_deprecation
ActiveModelSerializers::Adapter.create(resource, options)
end

def adapter_class(adapter)
warn_deprecation
ActiveModelSerializers::Adapter.adapter_class(adapter)
end

def adapter_map
warn_deprecation
ActiveModelSerializers::Adapter.adapter_map
end

def adapters
warn_deprecation
ActiveModelSerializers::Adapter.adapters
end

def register(name, klass = name)
warn_deprecation
ActiveModelSerializers::Adapter.register(name, klass)
end

def lookup(adapter)
warn_deprecation
ActiveModelSerializers::Adapter.lookup(adapter)
end

def warn_deprecation
warn "Calling deprecated #{name} (#{__FILE__}) from #{caller[1..3].join(', ')}. Please use ActiveModelSerializers::Adapter"
end
private :warn_deprecation
end

require 'active_model/serializer/adapter/base'
require 'active_model/serializer/adapter/null'
require 'active_model/serializer/adapter/attributes'
require 'active_model/serializer/adapter/json'
require 'active_model/serializer/adapter/json_api'
end
end
end
14 changes: 14 additions & 0 deletions lib/active_model/serializer/adapter/attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_model_serializers/adapter/attributes'

module ActiveModel
class Serializer
module Adapter
class Attributes < DelegateClass(ActiveModelSerializers::Adapter::Attributes)
def initialize(serializer, options = {})
warn "Calling deprecated #{self.class.name} (#{__FILE__}) from #{caller[0..2].join(', ')}. Please use #{self.class.name.sub('ActiveModel::Serializer', 'ActiveModelSerializers')}"
super(ActiveModelSerializers::Adapter::Attributes.new(serializer, options))
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/active_model/serializer/adapter/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module ActiveModel
class Serializer
module Adapter
class Base < DelegateClass(ActiveModelSerializers::Adapter::Base)
def self.inherited(base)
warn "Inheriting deprecated ActiveModel::Serializer::Adapter::Base in #{caller[0..2].join(', ')}. Please use ActiveModelSerializers::Adapter::Base"
super
end

def initialize(serializer, options = {})
super(ActiveModelSerializers::Adapter::Base.new(serializer, options))
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/active_model/serializer/adapter/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_model_serializers/adapter/json'

module ActiveModel
class Serializer
module Adapter
class Json < DelegateClass(ActiveModelSerializers::Adapter::Json)
def initialize(serializer, options = {})
warn "Calling deprecated #{self.class.name} (#{__FILE__}) from #{caller[0..2].join(', ')}. Please use #{self.class.name.sub('ActiveModel::Serializer', 'ActiveModelSerializers')}"
super(ActiveModelSerializers::Adapter::Json.new(serializer, options))
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/active_model/serializer/adapter/json_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_model_serializers/adapter/json_api'

module ActiveModel
class Serializer
module Adapter
class JsonApi < DelegateClass(ActiveModelSerializers::Adapter::JsonApi)
def initialize(serializer, options = {})
warn "Calling deprecated #{self.class.name} (#{__FILE__}) from #{caller[0..2].join(', ')}. Please use #{self.class.name.sub('ActiveModel::Serializer', 'ActiveModelSerializers')}"
super(ActiveModelSerializers::Adapter::JsonApi.new(serializer, options))
end
end
end
end
end
13 changes: 0 additions & 13 deletions lib/active_model/serializer/adapter/json_api/api_objects.rb

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions lib/active_model/serializer/adapter/json_api/meta.rb

This file was deleted.

14 changes: 14 additions & 0 deletions lib/active_model/serializer/adapter/null.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_model_serializers/adapter/null'

module ActiveModel
class Serializer
module Adapter
class Null < DelegateClass(ActiveModelSerializers::Adapter::Null)
def initialize(serializer, options = {})
warn "Calling deprecated #{self.class.name} (#{__FILE__}) from #{caller[0..2].join(', ')}. Please use #{self.class.name.sub('ActiveModel::Serializer', 'ActiveModelSerializers')}"
super(ActiveModelSerializers::Adapter::Null.new(serializer, options))
end
end
end
end
end
15 changes: 8 additions & 7 deletions lib/active_model_serializers/adapter/json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class JsonApi < Base
autoload :PaginationLinks
autoload :FragmentCache
autoload :Link
require 'active_model/serializer/adapter/json_api/meta'
autoload :Deserialization
require 'active_model/serializer/adapter/json_api/api_objects'
autoload :Meta
autoload :ResourceIdentifier
autoload :Relationship
autoload :Error
autoload :Deserialization

# TODO: if we like this abstraction and other API objects to it,
# then extract to its own file and require it.
Expand Down Expand Up @@ -134,7 +135,7 @@ def resource_objects_for(serializers)
end

def process_resource(serializer, primary)
resource_identifier = ActiveModel::Serializer::Adapter::JsonApi::ApiObjects::ResourceIdentifier.new(serializer).as_json
resource_identifier = ResourceIdentifier.new(serializer).as_json
return false unless @resource_identifiers.add?(resource_identifier)

resource_object = resource_object_for(serializer)
Expand Down Expand Up @@ -172,7 +173,7 @@ def attributes_for(serializer, fields)
# {http://jsonapi.org/format/#document-resource-objects Document Resource Objects}
def resource_object_for(serializer)
resource_object = cache_check(serializer) do
resource_object = ActiveModel::Serializer::Adapter::JsonApi::ApiObjects::ResourceIdentifier.new(serializer).as_json
resource_object = ResourceIdentifier.new(serializer).as_json

requested_fields = fieldset && fieldset.fields_for(resource_object[:type])
attributes = attributes_for(serializer, requested_fields)
Expand All @@ -197,7 +198,7 @@ def resource_object_for(serializer)
def relationships_for(serializer, requested_associations)
include_tree = ActiveModel::Serializer::IncludeTree.from_include_args(requested_associations)
serializer.associations(include_tree).each_with_object({}) do |association, hash|
hash[association.key] = ActiveModel::Serializer::Adapter::JsonApi::ApiObjects::Relationship.new(
hash[association.key] = Relationship.new(
serializer,
association.serializer,
association.options,
Expand All @@ -221,7 +222,7 @@ def pagination_links_for(serializer, options)

# {http://jsonapi.org/format/#document-meta Docment Meta}
def meta_for(serializer)
ActiveModel::Serializer::Adapter::JsonApi::Meta.new(serializer).as_json
Meta.new(serializer).as_json
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions lib/active_model_serializers/adapter/json_api/meta.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module ActiveModelSerializers
module Adapter
class JsonApi
class Meta
def initialize(serializer)
@object = serializer.object
@scope = serializer.scope

# Use the return value of the block unless it is nil.
if serializer._meta.respond_to?(:call)
@value = instance_eval(&serializer._meta)
else
@value = serializer._meta
end
end

def as_json
@value
end

protected

attr_reader :object, :scope
end
end
end
end
Loading

0 comments on commit dd94fe2

Please sign in to comment.