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

Enable use of ActiveSupport::StringInquirer as an ActiveRecord::Serialization coder #5586

Closed
wants to merge 1 commit into from
Closed

Enable use of ActiveSupport::StringInquirer as an ActiveRecord::Serialization coder #5586

wants to merge 1 commit into from

Conversation

laserlemon
Copy link
Contributor

The purpose of this is to allow ActiveSupport::StringInquirer to be used alongside ActiveRecord's serialize method, like so:

class Car < ActiveRecord::Base
  serialize :color, ActiveSupport::StringInquirer
end

car = Car.create(color: "red")
car.color.red? # => true

Because this straddles the line between ActiveSupport and ActiveRecord, I wasn't exactly sure of the proper place for this, so I'm certainly willing to move it around if need be.

@drogus
Copy link
Member

drogus commented Mar 27, 2012

@laserlemon thanks for the patch, but if we merge this, we will need to also accept pull requests with dump and load methods added to a lot of the other classes as well. If you need to serialize classes that do not support it by default, please just make a subclass and implement needed methods there.

@laserlemon
Copy link
Contributor Author

Bummer. Thank you for the consideration anyway!

@drogus
Copy link
Member

drogus commented Mar 27, 2012

@laserlemon btw, I would do it like this:

def color
  value = super
  ActiveSupport::StringInquirer.new(value) if value
end

But I guess it's a matter of taste.

@drogus drogus closed this Mar 27, 2012
@laserlemon
Copy link
Contributor Author

@drogus Thank you. Yes, that's how I've done it in the past.

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

Successfully merging this pull request may close these issues.

None yet

2 participants