-
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
Remove support for liquid_methods
Module extension
#568
Conversation
I'm cool with this. Need to have a clear blurb stating the migration path - dunno if this goes in the changelog or elsewhere. |
👍 this could easily live outside of liquid if anyone cares about it. |
Remove support for `liquid_methods` Module extension
This has just gone 'live' in version 4, though this makes sense, what's the suggested migration path? Or, how would one properly implement this without the use of liquid_methods? |
It's recommended to create drop classes explicitly. What it was doing under the hood was rather simple: https://github.com/Shopify/liquid/pull/568/files#diff-c54ab82e2cb4832484af67335d101514L45 |
Allright, understood. In the meantime if anyone wants a migration path (in case of Rails) drop this in a concern and include it in your models: module LiquidMethods
extend ActiveSupport::Concern
module ClassMethods
def liquid_methods(*allowed_methods)
drop_class = eval "class #{self}::LiquidDropClass < Liquid::Drop; self; end"
define_method :to_liquid do
drop_class.new(self)
end
drop_class.class_eval do
def initialize(object)
@object = object
end
allowed_methods.each do |sym|
define_method sym do
@object.send sym
end
end
end
end
end
end |
Is this correct? class Banana < ApplicationRecord
- liquid_methods :variety, :mass, :deliciousness
+ class LiquidDropBanana < Liquid::Drop
+ def initialize(banana)
+ @banana = banana
+ end
+
+ delegate :variety, :mass, :deliciousness, to: :@banana
+ end
+
+ def to_liquid
+ LiquidDropBanana.new(self)
+ end If so,
Thanks. |
Do whatever you feel is appropriate.
https://github.com/Shopify/liquid/wiki/Introduction-to-Drops |
I did not receive an answer on this, but what I showed above passes my tests. ¯_(ツ)_/¯
I went with
Thanks, I was looking in http://docs.shopify.com/themes/liquid-basics Other than this issue, upgrade to liquid 4 seems to have gone well, will report back if I find anything else. |
The discussion in Shopify#568 helped me. [ci skip]
Say I had a relation off a parent drop (Rails). The parent drop has a |
It would be more robust to define |
I think this is ugly and should be discouraged.
@arthurnn @pushrax @dylanahsmith