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)

Could be spun out to sublclasses but



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/concerns/roles/person.rb', line 67

def 
  if y = year_active_year
    person.year_active_start = [y, person.year_active_start].compact.map(&:to_i).min
    person.year_active_end = [y, person.year_active_end].compact.map(&:to_i).max

    if person.valid?
      person.save
    else
      person.year_active_start = person.year_active_start_before_last_save
      person.year_active_end = person.year_active_end_before_last_save
    end
  end
  true
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

#year_active_yearYear? (protected)

The largest year attribte in the RoleObject

Set in Role subclasses

Returns:

  • (Year, nil)

    used to compare and update Person active_start/end values



62
63
64
# File 'app/models/concerns/roles/person.rb', line 62

def year_active_year
  nil
end