kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

[Text normalizer] Description could an object, not a string #175

Closed thebravoman closed 5 years ago

thebravoman commented 6 years ago

I have another object from another gem that is called @page_description and it is not a string. It is an active record. So could we call description.to_str and thus allow other objects to be passed.

kpumuk commented 5 years ago

I like the idea. My main concern is that if you send an object by accident, it will throw a confusing error like:

NoMethodError: undefined method `to_str' for #<User:0x00007fda326480e8>

What do you think about moving this change to cleanup_string method, and also adding a validation? Like


    def cleanup_string(string)
      raise ArgumentError, 'Expected a string or an object that implements #to_str' unless string.respond_to?(:to_str)
      strip_tags(string.to_str).gsub(/\s+/, ' ').strip.html_safe
    end
kpumuk commented 5 years ago

Merged within https://github.com/kpumuk/meta-tags/pull/183