lib/institutions.rb in institutions-0.0.3 vs lib/institutions.rb in institutions-0.0.4
- old
+ new
@@ -9,24 +9,29 @@
DEFAULT_FILENAME = "institutions.yml"
def self.loadpaths
@loadpaths ||=
[(defined?(::Rails) and ::Rails.version >= '3.0.1' ) ?
- "#{Rails.root}/config" : DEFAULT_LOADPATH]
+ self.rails_loadpath : DEFAULT_LOADPATH]
end
+ # Necessary to use a proc to generate the rails root a bit later.
+ def self.rails_loadpath
+ lambda {return "#{Rails.root}/config"}
+ end
+
def self.filenames
@filenames ||= [DEFAULT_FILENAME]
end
# Intended for internal use only.
def self.loadfiles
loadfiles = []
if loadfiles.empty?
loadpaths.each do |loadpath|
filenames.each do |filename|
- loadfile = File.join(loadpath, filename)
+ loadfile = File.join((loadpath.is_a? Proc) ? loadpath.call : loadpath, filename)
loadfiles<< loadfile if File.exists?(loadfile)
end
end
end
loadfiles
@@ -70,10 +75,10 @@
code = code.to_sym
# Merge the new elements or add a new Institution
@institutions.has_key?(code) ?
@institutions[code].merge(elements) :
@institutions[code] =
- Institution.new(code, elements["name"] ? elements["name"] : code, elements)
+ Institution.new(code, elements["name"] ? elements["name"] : code.to_s, elements)
end
end
# Handle inheritance for institutions
merge_parents
end
\ No newline at end of file