Sha256: 9ee3b99beb90d6532f076744b7ef1e096c28ca8b70dbd9f4041d61fdab474c4d

Contents?: true

Size: 736 Bytes

Versions: 5

Compression:

Stored size: 736 Bytes

Contents

module DateBook
  module ActsAsOwnable
    def acts_as_ownable(options = {})
      # Rolify Gem
      resourcify

      scope :readable_by, ->(user) { accessible_by(::Ability.new(user)) }

      include InstanceMethods
    end

    module InstanceMethods
      def owners
        User.with_role(:owner, self)
      end

      def owners=(revised_owners)
        # Remove owners not listed in new value
        owners.each do |owner|
          owner.remove_role(:owner, self) unless revised_owners.include? owner
        end
        # Add owners not previously held
        revised_owners.each do |revised_owner|
          revised_owner.add_role(:owner, self) unless owners.include? revised_owner
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
date_book-0.0.6 lib/date_book/concerns/acts_as_ownable.rb
date_book-0.0.5 lib/date_book/concerns/acts_as_ownable.rb
date_book-0.0.3 lib/date_book/concerns/acts_as_ownable.rb
date_book-0.0.2 lib/date_book/concerns/acts_as_ownable.rb
date_book-0.0.1 lib/date_book/concerns/acts_as_ownable.rb