-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1559 from groyoh/deperecation_dsl
Deperecation dsl
- Loading branch information
Showing
11 changed files
with
95 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
require 'active_model/serializer/collection_serializer' | ||
class ActiveModel::Serializer | ||
class ArraySerializer < CollectionSerializer | ||
def initialize(*) | ||
warn "Calling deprecated ArraySerializer in #{caller[0..2].join(', ')}. Please use CollectionSerializer" | ||
super | ||
class << self | ||
extend ActiveModelSerializers::Deprecate | ||
deprecate :new, 'ActiveModel::CollectionSerializer.' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## | ||
# Provides a single method +deprecate+ to be used to declare when | ||
# something is going away. | ||
# | ||
# class Legacy | ||
# def self.klass_method | ||
# # ... | ||
# end | ||
# | ||
# def instance_method | ||
# # ... | ||
# end | ||
# | ||
# extend ActiveModelSerializers::Deprecate | ||
# deprecate :instance_method, "ActiveModelSerializers::NewPlace#new_method" | ||
# | ||
# class << self | ||
# extend ActiveModelSerializers::Deprecate | ||
# deprecate :klass_method, :none | ||
# end | ||
# end | ||
# | ||
# Adapted from https://github.com/rubygems/rubygems/blob/1591331/lib/rubygems/deprecate.rb | ||
module ActiveModelSerializers | ||
module Deprecate | ||
## | ||
# Simple deprecation method that deprecates +name+ by wrapping it up | ||
# in a dummy method. It warns on each call to the dummy method | ||
# telling the user of +replacement+ (unless +replacement+ is :none) that it is planned to go away. | ||
|
||
def deprecate(name, replacement) | ||
old = "_deprecated_#{name}" | ||
alias_method old, name | ||
class_eval do | ||
define_method(name) do |*args, &block| | ||
target = self.is_a?(Module) ? "#{self}." : "#{self.class}#" | ||
msg = ["NOTE: #{target}#{name} is deprecated", | ||
replacement == :none ? ' with no replacement' : "; use #{replacement} instead", | ||
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}" | ||
] | ||
warn "#{msg.join}." | ||
send old, *args, &block | ||
end | ||
end | ||
end | ||
|
||
module_function :deprecate | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters