Sha256: 5045a69920b0adcfbc0fba384eccc8e6298bfd337300948ed7caf0d8b2d3284a
Contents?: true
Size: 1.07 KB
Versions: 9
Compression:
Stored size: 1.07 KB
Contents
module CanTango module Ability module Cache class SimpleKey attr_reader :user, :subject # FIX: do we really need both user and subject? how about just candidate! def initialize user, subject = nil @user = user @subject = subject || user end def self.create_for ability self.new ability.user, ability.subject end def value raise "No key could be generated for User:#{user.inspect} and Subject:#{subject} - key field: #{user_key_field}" if !user_key @value ||= user_key.hash end def to_s "key hash: #{value}" end protected def user_key # raise "#{user.class} must have a method ##{user_key_field}. You can configure this with CanTango.config#user.unique_key_field" if !user.respond_to?(user_key_field) user.send(user_key_field) if user.respond_to? user_key_field end def user_key_field CanTango.config.user.unique_key_field || :email end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems