Sha256: 22787e3915fb4f6883eb4d624453e58acc88833d4fcb1d00e9080423257dd239

Contents?: true

Size: 719 Bytes

Versions: 2

Compression:

Stored size: 719 Bytes

Contents

module Camaraderie
  module Membership
    extend ActiveSupport::Concern
    included do
      # Associations
      belongs_to :user, validate: true
      belongs_to :organization

      # Validations
      validates :user, presence: true
      validates :organization, presence: true
      validates :membership_type, presence: true, inclusion: { in: Camaraderie.membership_types }, uniqueness: { scope: [:user_id, :organization_id] }

      # Scopes
      Camaraderie.membership_types.each do |type|
        scope type.pluralize, lambda { where(membership_type: type) }
      end

      # Nested attributes
      accepts_nested_attributes_for :user
      accepts_nested_attributes_for :organization
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
camaraderie-0.1.3 lib/camaraderie/membership.rb
camaraderie-0.1.2 lib/camaraderie/membership.rb