Skip to content

Commit

Permalink
Merge pull request #388 from marcosddourado/refatoring_repositories_c…
Browse files Browse the repository at this point in the history
…ontroller

refactor latest method
  • Loading branch information
diegoamc authored Nov 5, 2016
2 parents a5f2d20 + 1590cd8 commit 89217bb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/models/concerns/has_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions app/models/kalibro_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89217bb

Please sign in to comment.