Created
September 3, 2013 23:41
-
-
Save jordaaash/6431058 to your computer and use it in GitHub Desktop.
This file contains 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 FilterJson | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def filter_json (*attributes) | |
(@filter_attributes ||= Set.new).merge(attributes.map { |a| a.to_s }) | |
end | |
def filter_attributes | |
if superclass.respond_to?(:filter_attributes) | |
superclass.filter_attributes + @filter_attributes | |
else | |
@filter_attributes | |
end | |
end | |
end | |
def as_json (options = nil) | |
options ||= {} | |
super(options.deep_merge({:except => self.class.filter_attributes.to_a})) | |
end | |
end |
This file contains 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 SecurePassword | |
extend ActiveSupport::Concern | |
include FilterJson | |
included do | |
has_secure_password :validations => false | |
filter_json :password_digest | |
#... | |
end | |
#... | |
end |
This file contains 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
class User < ActiveRecord::Base | |
include SecurePassword | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment