lib/smilodon.rb in smilodon-0.2.7 vs lib/smilodon.rb in smilodon-0.2.8

- old
+ new

@@ -45,15 +45,20 @@ # Setup the logger to log populator warnings and messages. self.logger = PopulateLogger.setup options = args.last.is_a?(Hash) ? args.pop : {} - self.files = args - self.directory = options[:directory] || DIRECTORY + + self.directory = if defined?(Rails) + "#{Rails.root}/#{options[:directory] || DIRECTORY}" + else + options[:directory] || DIRECTORY + end self.type = options[:type] || TYPE self.header = options[:header] self.before = options[:before] + self.files = args.empty? ? grab_files : args end # Parses the data file content and processes each row. # # @return [Boolean] Returns true if all rows are processed successfully. @@ -85,11 +90,17 @@ def process(row = nil) raise MethodNotOverridden end private - + + def grab_files + Dir.glob("#{directory}/*").map do |file| + File.basename(file, File.extname(file)) + end + end + # The parser to use based on the type of data file. # # @param [String] Name of file to be read # @return [Parser, #parse] Returns the parser class to use. def parser @@ -101,14 +112,10 @@ # Absolute path for the data file. # # @return [String] The absolute path. def path(file) - if defined?(Rails) - "#{Rails.root}/#{directory}/#{file}.#{type}" - else - "#{directory}/#{file}.#{type}" - end + "#{directory}/#{file}.#{type}" end # Reads the data file. # # @param [String] Name of file to be read