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

Current implementation creates a Singleton class and prevents marshaling #16

Open
mynock opened this issue May 18, 2015 · 2 comments
Open

Comments

@mynock
Copy link

mynock commented May 18, 2015

This line:
eval "class <<str; def html_truncated?; #{opts[:was_truncated]} end end"

causes a singleton class to be returned which prevents the field from being serialized using Marshal (and therefore prevents it from being cached using dalli/memcached).

@nono
Copy link
Owner

nono commented May 19, 2015

OK, thanks for the information. What do you suggest?

meineerde added a commit to planio-gmbh/HTML-Truncator that referenced this issue Jul 22, 2016
This feature broke marshaling which is required for caching of truncated
strings. Fixes nono#16
@majkelcc
Copy link

majkelcc commented Mar 8, 2019

Wouldn't creating a class inheriting from String with htm_truncated? method solve this problem?

Something like:

class HTML_Truncator::Output < String
  def initialize(str, truncated)
    @truncated = truncated
    super(str)
  end

  def html_truncated?
    @truncated
  end
end

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

3 participants