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

Allow overriding blank? method in drops #1812

Open
h0jeZvgoxFepBQ2C opened this issue Jul 5, 2024 · 1 comment
Open

Allow overriding blank? method in drops #1812

h0jeZvgoxFepBQ2C opened this issue Jul 5, 2024 · 1 comment

Comments

@h0jeZvgoxFepBQ2C
Copy link

Hi,

we just figured out that overriding the methods blank? or present? doesn't work to be overriden in drops, f.e. we would like to do following:

{% if user.account %}
{% else %}
{% endif %}
class AccountDrop < Liquid::Drop
  def initialize(account)
    @account = account
  end

   def blank?
    @account.blank?
  end
end

But it seems that this is not working? Also not with delegate or defs_delegators via forwardable ruby standard module?

@h0jeZvgoxFepBQ2C
Copy link
Author

h0jeZvgoxFepBQ2C commented Jul 5, 2024

It seems that you can at least overwrite the invokable methods:

class AccountDrop < Liquid::Drop

  delegate :blank?, :present?, to: :@account

  def initialize(account)
    @account = account
  end

  def self.invokable_methods
      super_methods = super()
      custom_methods = Set.new(%w[blank? present?])
      super_methods + custom_methods
    end
end

So at least following works now:

{% if user.account.present? %}
{% else %}
{% endif %}

but this still not?

{% if user.account %}
{% else %}
{% endif %}

Any ideas on how to make this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant