diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6f8b2e..7cfab116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The version numbers below try to follow the conventions at http://semver.org/. ## Unreleased +- Refactor latest method - Remove the repository's instance that has remained in the db - Adding translation of the periodicity options in repository helper - Fixing wrong configurations translation in portuguese navbar diff --git a/app/models/concerns/has_owner.rb b/app/models/concerns/has_owner.rb index eb6ccbf1..79c50d41 100644 --- a/app/models/concerns/has_owner.rb +++ b/app/models/concerns/has_owner.rb @@ -4,6 +4,13 @@ module HasOwner extend ActiveSupport::Concern class_methods do + def latest(count = 1) + all.sort { |one, another| another.id <=> one.id }.select { |entity| + attributes = entity.attributes + attributes && attributes.public + }.first(count) + end + def public_or_owned_by_user(user = nil) class_name = name+"Attributes" collection = class_name.constantize.where(public: true) diff --git a/app/models/kalibro_configuration.rb b/app/models/kalibro_configuration.rb index 7d534656..e4855b22 100644 --- a/app/models/kalibro_configuration.rb +++ b/app/models/kalibro_configuration.rb @@ -8,13 +8,6 @@ def self.public self.public_or_owned_by_user end - def self.latest(count = 1) - all.sort { |one, another| another.id <=> one.id }.select { |kalibro_configuration| - attributes = kalibro_configuration.attributes - attributes && attributes.public - }.first(count) - end - def attributes @attributes ||= KalibroConfigurationAttributes.find_by(kalibro_configuration_id: self.id) end diff --git a/app/models/project.rb b/app/models/project.rb index ed3bde86..3dd68516 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -4,13 +4,6 @@ class Project < KalibroClient::Entities::Processor::Project attr_writer :attributes - def self.latest(count = 1) - all.sort { |one, another| another.id <=> one.id }.select { |project| - attributes = project.attributes - attributes && attributes.public - }.first(count) - end - def attributes @attributes ||= ProjectAttributes.find_by_project_id(@id) end diff --git a/app/models/repository.rb b/app/models/repository.rb index d502a10a..e839fbb1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,10 +4,6 @@ class Repository < KalibroClient::Entities::Processor::Repository attr_writer :attributes - def self.latest(count=1) - all.sort { |one, another| another.id <=> one.id }.select { |repository| repository.attributes.public }.first(count) - end - def attributes @attributes ||= RepositoryAttributes.find_by_repository_id(@id) end