From 2e1cac5676b6732b45429815daf6282aee1d83b6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 27 May 2011 11:28:43 -0500 Subject: [PATCH] Accept both Arrays and Hashs --- lib/linguist/repository.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 2dfd52b3..536f825c 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -8,23 +8,26 @@ module Linguist # # Returns a Repository def self.from_directory(base_path) - paths = Dir["#{base_path}/**/*"].inject({}) do |h, path| - if File.file?(path) - blob = FileBlob.new(path, base_path) - h[blob.name] = blob - end - h - end - new(paths) + new Dir["#{base_path}/**/*"]. + select { |f| File.file?(f) }. + map { |path| FileBlob.new(path, base_path) } end # Public: Initialize a new Repository # - # paths - A Hash of String path keys and Blob values. + # paths - An Array of Blob objects or a Hash of String path keys + # and Blob values. # # Returns a Repository def initialize(paths) - @paths = paths + if paths.is_a?(Array) + @paths = paths.inject({}) do |h, blob| + h[blob.name] = blob + h + end + else + @paths = paths + end @computed_stats = false @language = @size = nil