Commit a14b98f8 authored by tiagonbotelho's avatar tiagonbotelho Committed by Yorick Peterse

implements project languages saving them onto the database

parent d9e646a7
...@@ -86,6 +86,18 @@ class Project < ActiveRecord::Base ...@@ -86,6 +86,18 @@ class Project < ActiveRecord::Base
end end
end end
# checks if the language main language of the project changed
before_save :check_main_language
def check_main_language
if !repository.empty? && self.changed?
language = Linguist::Repository.new(
repository.rugged,
repository.rugged.head.target_id).language
self.main_language = language
end
end
ActsAsTaggableOn.strict_case_match = true ActsAsTaggableOn.strict_case_match = true
acts_as_taggable_on :tags acts_as_taggable_on :tags
......
class AddMainLanguageToRepository < ActiveRecord::Migration
require 'rugged'
require 'linguist'
def up
add_column :projects, :main_language, :string, default: nil
Project.all.each do |project|
unless project.repository.empty?
language = Linguist::Repository.new(
project.repository.rugged,
project.repository.rugged.head.target_id).language
project.update_attributes(main_language: language)
end
end
end
def down
remove_column :projects, :main_language
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment