Adding basic find_by_id functionality to Language

This commit is contained in:
Arfon Smith
2016-09-13 11:09:05 -07:00
parent 1f43664a51
commit a3227c2c27
2 changed files with 26 additions and 4 deletions

View File

@@ -20,10 +20,11 @@ module Linguist
#
# Languages are defined in `lib/linguist/languages.yml`.
class Language
@languages = []
@index = {}
@name_index = {}
@alias_index = {}
@languages = []
@index = {}
@name_index = {}
@alias_index = {}
@language_id_index = {}
@extension_index = Hash.new { |h,k| h[k] = [] }
@interpreter_index = Hash.new { |h,k| h[k] = [] }
@@ -84,6 +85,8 @@ module Linguist
@filename_index[filename] << language
end
@language_id_index[language.language_id] = language
language
end
@@ -193,6 +196,19 @@ module Linguist
@interpreter_index[interpreter]
end
# Public: Look up Languages by its language_id.
#
# language_id - Integer of language_id
#
# Examples
#
# Language.find_by_id(100)
# # => [#<Language name="Elixir">]
#
# Returns the matching Language
def self.find_by_id(language_id)
@language_id_index[language_id.to_i]
end
# Public: Look up Language by its name.
#