Sha256: 23b89fafc95f053c4964b058d65d8d73c91fff1abf86e182070bc3d7197347d1

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

module Pupa
  # A relationship between a person and an organization.
  class Membership < Base
    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

    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

8 entries across 8 versions & 1 rubygems

Version Path
pupa-0.0.8 lib/pupa/models/membership.rb
pupa-0.0.7 lib/pupa/models/membership.rb
pupa-0.0.6 lib/pupa/models/membership.rb
pupa-0.0.5 lib/pupa/models/membership.rb
pupa-0.0.4 lib/pupa/models/membership.rb
pupa-0.0.3 lib/pupa/models/membership.rb
pupa-0.0.2 lib/pupa/models/membership.rb
pupa-0.0.1 lib/pupa/models/membership.rb