Class: InstitutionList

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/authpds/institution_list.rb

Constant Summary collapse

@@institutions_yaml_path =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstitutionList

Returns a new instance of InstitutionList.



5
6
7
# File 'lib/authpds/institution_list.rb', line 5

def initialize
  @institutions = nil
end

Class Method Details

.institutions_defined?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/authpds/institution_list.rb', line 15

def self.institutions_defined?
  return !@@institutions_yaml_path.nil?
end

.yaml_path=(path) ⇒ Object

Used for initialization and testing



10
11
12
13
# File 'lib/authpds/institution_list.rb', line 10

def self.yaml_path=(path)
  @@institutions_yaml_path = path
  self.instance.reload
end

Instance Method Details

#default_institutionsObject

Returns an array of Institutions



25
26
27
# File 'lib/authpds/institution_list.rb', line 25

def default_institutions
  return institutions.values.find_all {|institution| institution.default_institution == true}
end

#get(name) ⇒ Object

Returns an Institution



20
21
22
# File 'lib/authpds/institution_list.rb', line 20

def get(name)
  return institutions[name]
end

#institutionsObject

Load institutions from the YAML file and return as a hash.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/authpds/institution_list.rb', line 42

def institutions
  unless @institutions
    raise ArgumentError.new("institutions_yaml_path was not specified.") if @@institutions_yaml_path.nil?
    raise NameError.new(
      "The file #{@@institutions_yaml_path} does not exist. "+
      "In order to use the institution feature you must create the file."
    ) unless File.exists?(@@institutions_yaml_path)
    institution_list = YAML.load_file( @@institutions_yaml_path )
    @institutions = {}
    # Turn the institution hashes to Institutions
    institution_list.each_pair do |institution_name, institution_hash|
      institution_hash["name"] = institution_name
      # Merge with parent institution
      institution_hash = 
      institution_list[institution_hash["parent_institution"]].
        merge(institution_hash) unless institution_hash["parent_institution"].nil?
      @institutions[institution_name] = Institution.new(institution_hash)
    end
  end
  return @institutions
end

#institutions_with_ip(ip) ⇒ Object

Returns an array of Institutions



30
31
32
# File 'lib/authpds/institution_list.rb', line 30

def institutions_with_ip(ip)
  return institutions.values.find_all { |institution| institution.includes_ip?(ip) }
end

#reloadObject

Reload institutions from the YAML file.



35
36
37
38
39
# File 'lib/authpds/institution_list.rb', line 35

def reload
  @institutions = nil
  institutions
  true
end