Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Created September 3, 2013 23:41
Show Gist options
  • Save jordaaash/6431058 to your computer and use it in GitHub Desktop.
Save jordaaash/6431058 to your computer and use it in GitHub Desktop.
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
module SecurePassword
extend ActiveSupport::Concern
include FilterJson
included do
has_secure_password :validations => false
filter_json :password_digest
#...
end
#...
end
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