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

adds swp and swo to gitignore and improves migration for project main_language

parent dc31aff3
...@@ -89,12 +89,8 @@ class Project < ActiveRecord::Base ...@@ -89,12 +89,8 @@ class Project < ActiveRecord::Base
# checks if the language main language of the project changed # checks if the language main language of the project changed
before_save :check_main_language before_save :check_main_language
def check_main_language def check_main_language
if !repository.empty? && self.changed? if commit_count.changed?
language = Linguist::Repository.new( self.main_language = repository.main_language
repository.rugged,
repository.rugged.head.target_id).language
self.main_language = language
end end
end end
...@@ -957,4 +953,14 @@ class Project < ActiveRecord::Base ...@@ -957,4 +953,14 @@ class Project < ActiveRecord::Base
def wiki def wiki
@wiki ||= ProjectWiki.new(self, self.owner) @wiki ||= ProjectWiki.new(self, self.owner)
end end
def main_language
language = read_attributes(:main_language)
return language if language
update_attributes(main_language: repository.main_language)
read_attributes(:main_language)
end
end end
...@@ -812,6 +812,12 @@ class Repository ...@@ -812,6 +812,12 @@ class Repository
raw_repository.ls_files(actual_ref) raw_repository.ls_files(actual_ref)
end end
def main_language
unless empty?
Linguist::Repository.new(rugged, rugged.head.target_id).language
end
end
private private
def cache def cache
......
class AddMainLanguageToRepository < ActiveRecord::Migration class AddMainLanguageToRepository < ActiveRecord::Migration
require 'rugged' def change
require 'linguist' add_column :projects, :main_language, :string
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
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