Sha256: 61a66f85bac57a8a0ec0667a22cca1d261f6f93c55a0895a6c5ad8e7a70d12f8

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

module Pupa
  # A relationship between a person and an organization.
  class Membership
    include Model

    self.schema = 'popolo/membership'

    include Concerns::Timestamps
    include Concerns::Sourceable
    include Concerns::Contactable
    include Concerns::Linkable

    attr_accessor :label, :role, :person_id, :organization_id, :post_id,
      :start_date, :end_date
    dump :label, :role, :person_id, :organization_id, :post_id,
      :start_date, :end_date

    foreign_key :person_id, :organization_id, :post_id

    # Returns the IDs of the parties to the relationship.
    #
    # @return [String] the IDs of the parties to the relationship
    def to_s
      "#{person_id} in #{organization_id}"
    end

    # A person's relationship with an organization must have a unique label,
    # though it may share a label with a historical relationship. Similarly, a
    # person may hold a post in an organization multiple times historically but
    # not simultaneously.
    def fingerprint
      hash = super
      {
        '$or' => [
          hash.slice(:label, :person_id, :organization_id, :end_date),
          hash.slice(:person_id, :organization_id, :post_id, :end_date),
        ],
      }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pupa-0.1.7 lib/pupa/models/membership.rb
pupa-0.1.6 lib/pupa/models/membership.rb
pupa-0.1.5 lib/pupa/models/membership.rb
pupa-0.1.4 lib/pupa/models/membership.rb
pupa-0.1.3 lib/pupa/models/membership.rb
pupa-0.1.2 lib/pupa/models/membership.rb
pupa-0.1.1 lib/pupa/models/membership.rb
pupa-0.1.0 lib/pupa/models/membership.rb
pupa-0.0.13 lib/pupa/models/membership.rb
pupa-0.0.12 lib/pupa/models/membership.rb
pupa-0.0.11 lib/pupa/models/membership.rb
pupa-0.0.10 lib/pupa/models/membership.rb
pupa-0.0.9 lib/pupa/models/membership.rb