-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Follow up to #1535 #1543
Follow up to #1535 #1543
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
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 |
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 |
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 = {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should be able to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I need to pass the non-deprecated adapter instance to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A naked 'super' passes along all args, as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like you're right |
||
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 |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bf4 is this what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically yes. I wasn't sure how it would work out.