From 074a77e6499fd03b0229efa7bf0005f1b0af5a32 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 2 Jul 2011 20:54:05 -0500 Subject: [PATCH] Allow any enum to be passed to Repository for stat collecting Fixes #28 --- lib/linguist/repository.rb | 28 +++++----------------------- test/test_repository.rb | 5 ----- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index b5e6eeb5..69f35f1d 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -20,35 +20,17 @@ module Linguist # Public: Initialize a new Repository # - # paths - An Array of Blob objects or a Hash of String path keys - # and Blob values. + # enum - Enumerator that responds to `each` and + # yields Blob objects # # Returns a Repository - def initialize(paths) - case paths - when Array - @paths = paths.inject({}) do |h, blob| - h[blob.name] = blob - h - end - when Hash - @paths = paths - else - raise ArgumentError, "#{paths.class} is not an Array or Hash" - end - + def initialize(enum) + @enum = enum @computed_stats = false @language = @size = nil @sizes = Hash.new { 0 } end - # Public: Lookup blob for path. - # - # Returns a Blob - def [](path) - @paths[path] - end - # Public: Returns a breakdown of language stats. # # Examples @@ -84,7 +66,7 @@ module Linguist def compute_stats return if @computed_stats - @paths.each do |path, blob| + @enum.each do |blob| # Skip vendored or generated blobs next if blob.vendored? || blob.generated? || blob.language.nil? diff --git a/test/test_repository.rb b/test/test_repository.rb index 2c8463fd..6b540789 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -13,11 +13,6 @@ class TestRepository < Test::Unit::TestCase repo(File.expand_path("../..", __FILE__)) end - def test_lookup_path - assert linguist_repo['lib/linguist.rb'] - assert_equal Language['Ruby'], linguist_repo['lib/linguist.rb'].language - end - def test_linguist_language assert_equal Language['JavaScript'], linguist_repo.language end