cirandas.net

ref: master

plugins/lattes_curriculum/lib/ext/person.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require_dependency 'person'

class Person

  attr_accessible :lattes_url, :academic_info_attributes

  has_one :academic_info

  after_destroy do |person|
    if !person.environment.nil? &&
person.environment.plugin_enabled?(LattesCurriculumPlugin) &&
!person.academic_info.nil?
      person.academic_info.destroy
    end
  end

  accepts_nested_attributes_for :academic_info

  def lattes_url
    if self.environment && self.environment.plugin_enabled?(LattesCurriculumPlugin)
      self.academic_info.nil? ? nil : self.academic_info.lattes_url
    end
  end

  def lattes_url= value
    if self.environment && self.environment.plugin_enabled?(LattesCurriculumPlugin)
      self.academic_info.lattes_url = value unless self.academic_info.nil?
    end
  end

  FIELDS << "lattes_url"
end