Class: ASF::ICLA

Inherits:
Object
  • Object
show all
Defined in:
lib/whimsy/asf/icla.rb

Constant Summary collapse

OFFICERS =
ASF::SVN.find('private/foundation/officers')
SOURCE =
OFFICERS ? "#{OFFICERS}/iclas.txt" : nil
@@mtime =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#claRefObject

cla name or SVN revision info



9
10
11
# File 'lib/whimsy/asf/icla.rb', line 9

def claRef
  @claRef
end

#emailObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



8
9
10
# File 'lib/whimsy/asf/icla.rb', line 8

def email
  @email
end

#formObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



8
9
10
# File 'lib/whimsy/asf/icla.rb', line 8

def form
  @form
end

#idObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



8
9
10
# File 'lib/whimsy/asf/icla.rb', line 8

def id
  @id
end

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



8
9
10
# File 'lib/whimsy/asf/icla.rb', line 8

def legal_name
  @legal_name
end

#nameObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



8
9
10
# File 'lib/whimsy/asf/icla.rb', line 8

def name
  @name
end

Class Method Details

.availidsObject

list of all ids



89
90
91
92
93
94
95
96
# File 'lib/whimsy/asf/icla.rb', line 89

def self.availids
  return unless SOURCE
  refresh
  return @@availids if @@availids
  availids = []
  each {|icla| availids << icla.id unless icla.id == 'notinavail'}
  @availids = availids
end

.each(&block) ⇒ Object

iterate over all of the ICLAs



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/whimsy/asf/icla.rb', line 99

def self.each(&block)
  refresh
  if @@id_index and not @@id_index.empty?
    @@id_index.values.each(&block)
  elsif @@email_index and not @@email_index.empty?
    @@email_index.values.each(&block)
  elsif @@name_index and not @@name_index.empty?
    @@name_index.values.each(&block)
  elsif SOURCE and File.exist?(SOURCE)
    File.read(SOURCE).scan(/^([-\w]+):(.*?):(.*?):(.*?):(.*)/).each do |list|
      icla = ICLA.new()
      icla.id = list[0]
      icla.legal_name = list[1]
      icla.name = list[2]
      icla.email = list[3]
      icla.form = list[4]
      match = icla.form.match(/^Signed CLA(?:;(\S+)| \((\+=.+)\))/)
      if match
        # match either the cla name or the SVN ref (+=...)
        icla.claRef = match[1] || match[2]
      end
      block.call(icla)
    end
  end
end

.find_by_email(value) ⇒ Object

find ICLA by email



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/whimsy/asf/icla.rb', line 64

def self.find_by_email(value)
  return unless SOURCE

  refresh
  unless @@email_index
    @@email_index = {}
    each {|icla| @@email_index[icla.email.downcase] = icla}
  end

  @@email_index[value.downcase]
end

.find_by_id(value) ⇒ Object

find ICLA by ID



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/whimsy/asf/icla.rb', line 51

def self.find_by_id(value)
  return if value == 'notinavail' or not SOURCE

  refresh
  unless @@id_index
    @@id_index = {}
    each {|icla| @@id_index[icla.id] = icla}
  end

  @@id_index[value]
end

.find_by_name(value) ⇒ Object

find ICLA by name



77
78
79
80
81
82
83
84
85
86
# File 'lib/whimsy/asf/icla.rb', line 77

def self.find_by_name(value)
  return unless SOURCE
  refresh
  unless @@name_index
    @@name_index = {}
    each {|icla| @@name_index[icla.name] = icla}
  end

  @@email_index[value]
end

.lname(line) ⇒ Object

rearrange line in an order suitable for sorting



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/whimsy/asf/icla.rb', line 126

def self.lname(line)
  return '' if line.start_with? '#'
  id, name, rest = line.split(':',3)
  return '' unless name

  # Drop trailing (comment string) or /* comment */
  name.sub! /\(.+\)$/,''
  name.sub! /\/\*.+\*\/$/,''
  return '' if name.strip.empty?

  name = ASF::Person.sortable_name(name)

  "#{name}:#{rest}"
end

.preloadObject

load ICLA information for every committer



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/whimsy/asf/icla.rb', line 38

def self.preload
  people = []
  each do |icla|
    unless icla.id == 'notinaval'
      person = ASF::Person.find(icla.id)
      people << person
      person.icla = icla
    end
  end
  people
end

.refreshObject

flush caches if source file changed



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/whimsy/asf/icla.rb', line 17

def self.refresh
  if not SOURCE or File.mtime(SOURCE) != @@mtime
    @@mtime = SOURCE ? File.mtime(SOURCE) : Time.now
    @@id_index = nil
    @@email_index = nil
    @@name_index = nil
    @@svn_change = nil

    @@availids = nil
  end
end

.sort(source) ⇒ Object

sort an entire iclas.txt file



142
143
144
145
146
147
148
# File 'lib/whimsy/asf/icla.rb', line 142

def self.sort(source)
  headers = source.scan(/^#.*/)
  lines = source.scan(/^\w.*/)

  headers.join("\n") + "\n" + 
    lines.sort_by {|line| lname(line + "\n")}.join("\n") + "\n"
end

.svn_changeObject



29
30
31
32
33
34
35
# File 'lib/whimsy/asf/icla.rb', line 29

def self.svn_change
  self.refresh
  if SOURCE
    @@svn_change ||= Time.parse(
      `svn info #{SOURCE}`[/Last Changed Date: (.*) \(/, 1]).gmtime
  end
end