Created
November 8, 2013 21:58
-
-
Save danbernier/7378358 to your computer and use it in GitHub Desktop.
A mix-in module for a Rails model that's backed by a column like `{column-name} ENUM('true', 'false')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HasFakeBooleanColumns | |
def self.wallpaper_over_fake(column_name) | |
define_method(column_name) do | |
self.attributes(column_name) == 'true' | |
end | |
define_method("#{column_name)=".to_sym) do |value| | |
self.update_attribute(column_name, value == 'true') | |
end | |
end | |
end | |
class MyModel | |
include HasFakeBooleanColumns | |
wallpaper_over_fake :column_name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment