Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
b4df06e3f098
Commit
a14b98f8
authored
Mar 01, 2016
by
tiagonbotelho
Committed by
Yorick Peterse
Mar 07, 2016
Browse files
implements project languages saving them onto the database
parent
f621a55d583d
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/.project.rb.swo
0 → 100644
View file @
b4df06e3
File added
app/models/project.rb
View file @
b4df06e3
...
...
@@ -86,6 +86,18 @@ def update_forks_visibility_level
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
acts_as_taggable_on
:tags
...
...
db/migrate/20160229193553_add_main_language_to_repository.rb
0 → 100644
View file @
b4df06e3
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment