Module: AuthClient::User::ClassMethods

Defined in:
lib/auth_client/user.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_auth_client_userObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/auth_client/user.rb', line 60

def acts_as_auth_client_user
  define_method :permissions do
    ::Permission.where :user_id => id
  end

  define_method(:has_permission?) do |role:, context: nil|
    context ?
      permissions.for_role(role).for_context(context).exists? :
      permissions.for_role(role).exists?
  end
end

#find_by(id:) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/auth_client/user.rb', line 72

def find_by(id:)
  redis_data = RedisUserConnector.get(id)

  return nil if (redis_data.nil? || redis_data.empty?)

  attributes = redis_data.merge(:id => id)

  build_user attributes
end