I have an ActiveRecord class called User. I'm trying to create a concern called Restrictable
which takes in some arguments like this:
class User < ActiveRecord::Base
include Restrictable # Would be nice to not need this line
restrictable except: [:id, :name, :email]
end
I want to then provide an instance method called restricted_data
which can perform some operation on those arguments and return some data. Example:
user = User.find(1)
user.restricted_data # Returns all columns except :id, :name, :email
How would I go about doing that?
If I understand your question correctly this is about how to write such a concern, and not about the actual return value of
restricted_data
. I would implement the concern skeleton as such:Then you can:
That would comply with the interface you designed, but the
except
key is a bit strange because it's actually restricting those values instead of allowing them.