Module: Invitation::Invitable

Defined in:
lib/invitation/invitable.rb

Overview

Any model you wish to invite users to join should extend this concern. This is typically an organization or resource with limited membership like an “account” or “project”.

Your code is responsible for managing associations between your Invitable and your user model.

For example, to make the model class Account an organization that can receive an invitation

class Account < ActiveRecord::Base
  invitable named_by: :name

  has_many :account_memberships
  has_many :users, through: :account_memberships
end

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#invitable(options = {}) ⇒ Object

All resources or organizations should be invitable.

Parameters:

  • options (Hash) (defaults to: {})
    • either named_by: <method name> or named: <String>


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/invitation/invitable.rb', line 22

def invitable(options = {})
  has_many :invites, as: :invitable
  class_attribute :invitable_options
  self.invitable_options = {}
  case
  when options[:named_by] then invitable_options[:named_by] = options[:named_by]
  when options[:named] then invitable_options[:named] = options[:named]
  else raise 'invitable requires options be set, either :name or :named_by. \
             e.g.: `invitable named: "string"` or `invitable named_by: :method_name`'
  end
  include Invitation::Invitable::InstanceMethods
end