Sha256: 991c68cc58704e79a0dcd22f74c8f90467612ad95c92c0bce6bebbb93fcf6902
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
class InstitutionList include Singleton # get the instance with InstitutionList.instance @@institutions_yaml_path = nil def initialize @institutions = nil end # Used for initialization and testing def self.yaml_path=(path) @@institutions_yaml_path = path self.instance.reload end def self.institutions_defined? return !@@institutions_yaml_path.nil? end # Returns an Institution def get(name) return institutions[name] end # Returns an array of Institutions def defautls return institutions.values.find_all {|institution| institution.defautl == true} end # Returns an array of Institutions def institutions_with_ip(ip) return institutions.values.find_all { |institution| institution.includes_ip?(ip) } end # Reload institutions from the YAML file. def reload @institutions = nil institutions true end # Load institutions from the YAML file and return as a hash. 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
authpds-0.0.15 | lib/authpds/institution_list.rb |