Module: Ownable::ActsAsOwnable::InstanceMethods

Defined in:
lib/ownable/acts_as_ownable.rb

Overview

Add owned_by? and belongs_to? to ActiveRecord subclasses

Instance Method Summary collapse

Instance Method Details

#belongs_to?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ownable/acts_as_ownable.rb', line 30

def belongs_to? candidate
  owned_by? candidate
end

#owned_by?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/ownable/acts_as_ownable.rb', line 22

def owned_by? candidate
  owner = find_owner

  return false if (owner.nil? || candidate.nil?)
  return candidate == owner.id if candidate.is_a? Fixnum
  return candidate == owner          
end