mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Accept both Arrays and Hashs
This commit is contained in:
@@ -8,23 +8,26 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns a Repository
|
# Returns a Repository
|
||||||
def self.from_directory(base_path)
|
def self.from_directory(base_path)
|
||||||
paths = Dir["#{base_path}/**/*"].inject({}) do |h, path|
|
new Dir["#{base_path}/**/*"].
|
||||||
if File.file?(path)
|
select { |f| File.file?(f) }.
|
||||||
blob = FileBlob.new(path, base_path)
|
map { |path| FileBlob.new(path, base_path) }
|
||||||
h[blob.name] = blob
|
|
||||||
end
|
|
||||||
h
|
|
||||||
end
|
|
||||||
new(paths)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Initialize a new Repository
|
# 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
|
# Returns a Repository
|
||||||
def initialize(paths)
|
def initialize(paths)
|
||||||
|
if paths.is_a?(Array)
|
||||||
|
@paths = paths.inject({}) do |h, blob|
|
||||||
|
h[blob.name] = blob
|
||||||
|
h
|
||||||
|
end
|
||||||
|
else
|
||||||
@paths = paths
|
@paths = paths
|
||||||
|
end
|
||||||
|
|
||||||
@computed_stats = false
|
@computed_stats = false
|
||||||
@language = @size = nil
|
@language = @size = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user