Skip to content

Instantly share code, notes, and snippets.

@danbernier
Created November 8, 2013 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbernier/7378358 to your computer and use it in GitHub Desktop.
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')
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