module ShareableModels::Models::Shareable

Define a model as shareable. A shareable model can be shared between other models called sharers. Imagine a platform with privates articles, you could want to share your awesome article with other person, so make it shareable.

Public Instance Methods

allow_edit(from, to) click to toggle source

Allow a sharer to edit the resource

Parameters:

from

Sharer that want to allow another to edit resource

to

Sharer that will be able to edit the resource

Returns:

True if it’s ok

# File lib/shareable_models/models/shareable.rb, line 127
def allow_edit(from, to)
  from.allow_edit(self, to)
end
editable_by?(from) click to toggle source

Check if a given sharer can edit this resource

Parameters:

from

Sharer that wants to edit the user.

Returns:

true if the sharer can edit it

# File lib/shareable_models/models/shareable.rb, line 97
def editable_by?(from)
  from.can_edit?(self)
end
leave_by(sharer) click to toggle source

Allow given sharer to leave the resource

Parameters:

sharer

Sharer that want to leave resource.

Returns:

True if it’s ok

# File lib/shareable_models/models/shareable.rb, line 79
def leave_by(sharer)
  sharer.leave(self)
end
prevent_edit(from, to) click to toggle source

Prevent a sharer to edit the resource. First parameter is to set same format of allow_edit.

Parameters:

from

Sharer that want to allow another to edit resource

to

Sharer that will be able to edit the resource

Returns:

True if it’s ok

# File lib/shareable_models/models/shareable.rb, line 144
def prevent_edit(from, to)
  from.prevent_edit(self, to)
end
readable_by?(from) click to toggle source

Check if a given sharer can see this resource

Parameters:

from

Sharer that wants to see the user.

Returns:

true if the sharer can see it

# File lib/shareable_models/models/shareable.rb, line 111
def readable_by?(from)
  from.can_read?(self)
end
share_it(from, to, edit = false) click to toggle source

Share current element with a sharer model.

Parameters:

from

Instance of model with share this resource

to

Instance of model to share with

edit

True if the user has edit permission. False by default

Returns:

true if its saved.

# File lib/shareable_models/models/shareable.rb, line 49
def share_it(from, to, edit = false)
  from.share(self, to, edit)
end
shareable?() click to toggle source

Method to determine if a model can be shared. It always true because the class includes this module.

Returns

true

# File lib/shareable_models/models/shareable.rb, line 23
def shareable?
  true
end
shareable_owner() click to toggle source

Return the shareable owner

# File lib/shareable_models/models/shareable.rb, line 30
def shareable_owner
  return nil if shareable_options.nil? || shareable_options[:owner].nil?
  send(shareable_options[:owner])
end
throw_out(from, to) click to toggle source

Throw out an user from this resource

Parameters:

from

Sharer that want to leave resource.

to

Sharer that want to leave resource.

Returns:

True if it’s ok

# File lib/shareable_models/models/shareable.rb, line 65
def throw_out(from, to)
  from.throw_out(self, to)
end