Module: Roles::Person

Extended by:
ActiveSupport::Concern
Included in:
Role
Defined in:
app/models/concerns/roles/person.rb

Instance Method Summary collapse

Instance Method Details

#check_for_lastObject (protected)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/concerns/roles/person.rb', line 30

def check_for_last
  if is_last_role? && role_object_type == 'Source'
    add_touch = false
    if type == 'SourceAuthor'
      role_object.update_columns(author: nil, cached_author_string: nil)
      add_touch = true
    end
    if type == 'SourceEditor'
      add_touch = true
      role_object.update_columns(editor: nil)
    end
    role_object.touch
  else
    role_object.send(:set_cached) if role_object.respond_to?(:set_cached, true)
  end
end

#person_role?Boolean (protected)

Returns:

  • (Boolean)


26
27
28
# File 'app/models/concerns/roles/person.rb', line 26

def person_role?
  person.present? && !organization
end

#update_person_year_metadataObject (protected)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/concerns/roles/person.rb', line 56

def 
  if role_object.respond_to?(:year)
    begin
      y = role_object.try(:year)
      y ||= role_object.try(:year_of_publication)

      yas = [y, person.year_active_start].compact.map(&:to_i).min
      yae = [y, person.year_active_end].compact.map(&:to_i).max

      person.update(
        year_active_end: yae,
        year_active_start: yas
      )

    rescue ActiveRecord::RecordInvalid
      # probably a year conflict, allow quietly
      # !? 
    end
  end
end

#vet_personObject (protected)

See /app/models/person.rb for a definition of vetted



48
49
50
51
52
53
54
# File 'app/models/concerns/roles/person.rb', line 48

def vet_person
  # Check whether there are one or more *other* roles besides this one, 
  # i.e. there are at least *2* for person_id
  if Role.where(person_id: person_id).where.not(id: id).any?
    person.update_column(:type, 'Person::Vetted') 
  end
end