Method: Linguist::Language#initialize

Defined in:
lib/linguist/language.rb

#initialize(attributes = {}) ⇒ Language

Internal: Initialize a new Language

attributes - A hash of attributes



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/linguist/language.rb', line 258

def initialize(attributes = {})
  # @name is required
  @name = attributes[:name] || raise(ArgumentError, "missing name")

  @fs_name = attributes[:fs_name]

  # Set type
  @type = attributes[:type] ? attributes[:type].to_sym : nil
  if @type && !get_types.include?(@type)
    raise ArgumentError, "invalid type: #{@type}"
  end

  @color = attributes[:color]

  # Set aliases
  @aliases = [default_alias] + (attributes[:aliases] || [])

  @tm_scope = attributes[:tm_scope] || 'none'
  @ace_mode = attributes[:ace_mode]
  @codemirror_mode = attributes[:codemirror_mode]
  @codemirror_mime_type = attributes[:codemirror_mime_type]
  @wrap = attributes[:wrap] || false

  # Set the language_id
  @language_id = attributes[:language_id]

  # Set extensions or default to [].
  @extensions   = attributes[:extensions]   || []
  @interpreters = attributes[:interpreters] || []
  @filenames    = attributes[:filenames]    || []

  # Set popular flag
  @popular    = attributes.key?(:popular)    ? attributes[:popular]    : false

  # If group name is set, save the name so we can lazy load it later
  if attributes[:group_name]
    @group_name = attributes[:group_name]

  # Otherwise we can set it to self now
  else
    @group_name = self.name
  end
end