Skip to content
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

Better deprecations for Spree::Core:: #9

Merged
merged 2 commits into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/app/models/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ def searcher_class=(sclass)
}

DEPRECATED_STORE_PREFERENCES.each do |old_preference_name, store_method|
# Avoid warning about implementation details
bc = ActiveSupport::BacktraceCleaner.new
bc.add_silencer { |line| line =~ %r{spree/preferences} }

# support all the old preference methods with a warning
define_method "preferred_#{old_preference_name}" do
ActiveSupport::Deprecation.warn("#{old_preference_name} is no longer supported on Spree::Config, please access it through #{store_method} on Spree::Store")
ActiveSupport::Deprecation.warn("#{old_preference_name} is no longer supported on Spree::Config, please access it through #{store_method} on Spree::Store", bc.clean(caller))
Store.default.send(store_method)
end
end
Expand Down
10 changes: 10 additions & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def self.config(&block)
module Core
autoload :ProductFilters, "spree/core/product_filters"

def self.const_missing(name)
case name
when :AdjustmentSource, :CalculatedAdjustments, :UserAddress, :UserPaymentSource
ActiveSupport::Deprecation.warn("Spree::Core::#{name} is deprecated! Use Spree::#{name} instead.", caller)
Spree.const_get(name)
else
super
end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this block is adding deprecation warnings on something that currently would just error? Is that a good thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tells programmers what and how to upgrade, rather than having to hunt down what is happening.

So I am 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems reasonable to me. @magnusvk ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 🇮🇹

class GatewayError < RuntimeError; end
class DestroyWithOrdersError < StandardError; end
end
Expand Down