module ActsAsShareable::Shareable::ClassMethods

Public Instance Methods

acts_as_shareable(options={}) click to toggle source

Specify the types that the shareable objects can be shared with

# File lib/acts_as_shareable/shareable.rb, line 18
def acts_as_shareable(options={})
  has_many :shares, :as => :shareable, :dependent => :destroy
  has_many :group_shares, -> {where(shared_to_type: 'Group')}, :as => :shareable, class_name: 'Share'
  has_many :user_shares, -> {where(shared_to_type: 'User')}, :as => :shareable, class_name: 'Share'
  has_many :shared_with_individual_users, through: :shares, source: :shared_to, source_type: 'User'
  has_many :shared_with_groups, through: :shares, source: :shared_to, source_type: 'Group'
  has_many :shared_with_group_users, through: :shared_with_groups, source: :users
  include ActsAsShareable::Shareable::InstanceMethods
  extend ActsAsShareable::Shareable::SingletonMethods
  accepts_nested_attributes_for :shares, allow_destroy: true
end