lib/institutions.rb in institutions-0.0.1 vs lib/institutions.rb in institutions-0.0.2
- old
+ new
@@ -3,21 +3,21 @@
module Institutions
require 'require_all'
require_rel 'institutions'
# Default paths/files for the module.
- DEFAULT_LOADPATHS = [
- (defined?(Rails) and Rails.root) ?
- "#{Rails.root}/config" : "./config" ]
- DEFAULT_FILENAMES = ["institutions.yml"]
+ DEFAULT_LOADPATH = "./config"
+ DEFAULT_FILENAME = "institutions.yml"
def self.loadpaths
- @loadpaths ||= DEFAULT_LOADPATHS.dup
+ @loadpaths ||=
+ [(defined?(::Rails) and ::Rails.version >= '3.0.1' ) ?
+ "#{Rails.root}/config" : DEFAULT_LOADPATH]
end
def self.filenames
- @filenames ||= DEFAULT_FILENAMES.dup
+ @filenames ||= [DEFAULT_FILENAME]
end
# Intended for internal use only.
def self.loadfiles
loadfiles = []
@@ -56,11 +56,11 @@
# "./config/institutions.yml"
# To manipulate load path order and/or add directories to the path
# Institutions.loadpaths << File.join("path", "to", "new", "load", "directory")
# To manipulate file name order and/or add file names
# Institutions.filenames << "newfile.yml"
- #
+ #
def self.institutions
unless @institutions
raise NameError.new("No load path was specified.") if loadpaths.nil?
raise NameError.new("No files named #{filenames} exist to load in the configured load paths, #{loadpaths}. ") if filenames.empty?
@institutions = {}
@@ -69,10 +69,10 @@
YAML.load_file(loadfile).each_pair do |code, elements|
code = code.to_sym
# Merge the new elements or add a new Institution
@institutions.has_key?(code) ?
@institutions[code].merge(elements) :
- @institutions[code] =
+ @institutions[code] =
Institution.new(code, elements["name"] ? elements["name"] : code, elements)
end
end
# Handle inheritance for institutions
merge_parents
\ No newline at end of file