Skip to content

Commit 70eee3a

Browse files
committed
Moved followed_repo out of namespace because User isn't a module. Refactored the users/github models to use explicit module/class declarations
1 parent b900166 commit 70eee3a

File tree

13 files changed

+121
-72
lines changed

13 files changed

+121
-72
lines changed

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def following_in_common(user)
710710
end
711711

712712
def followed_repos(since=2.months.ago)
713-
Redis.current.zrevrange(followed_repo_key, 0, since.to_i).collect { |link| FollowedRepo.new(link) }
713+
Redis.current.zrevrange(followed_repo_key, 0, since.to_i).collect { |link| Users::Github::FollowedRepo.new(link) }
714714
end
715715

716716
def networks

app/models/user/followed_repo.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/models/users/github.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module Users::Github
2-
def self.table_name_prefix
3-
'users_github_'
1+
module Users
2+
module Github
3+
def self.table_name_prefix
4+
'users_github_'
5+
end
46
end
57
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Users
2+
module Github
3+
class FollowedRepo
4+
attr_reader :data
5+
6+
def initialize(data)
7+
@data = JSON.parse(data)
8+
end
9+
10+
def description
11+
data['description']
12+
end
13+
14+
def repo
15+
data['link'].gsub('https://github.com/', '')
16+
end
17+
18+
def date
19+
@date ||= Date.parse(data['date'])
20+
end
21+
22+
def link
23+
data['link']
24+
end
25+
26+
def user
27+
User.find(data['user_id'])
28+
end
29+
end
30+
end
31+
end
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
module Users::Github::Organizations
2-
def self.table_name_prefix
3-
'users_github_organizations_'
1+
module Users
2+
module Github
3+
module Organizations
4+
def self.table_name_prefix
5+
'users_github_organizations_'
6+
end
7+
end
48
end
59
end

app/models/users/github/organizations/follower.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
class Users::Github::Organizations::Follower < ActiveRecord::Base
2-
belongs_to :profile, :class_name => 'Users::Github::Profile'
3-
belongs_to :organization, :class_name => 'Users::Github::Organization'
1+
module Users
2+
module Github
3+
module Organizations
4+
class Follower < ActiveRecord::Base
5+
belongs_to :profile, :class_name => 'Users::Github::Profile'
6+
belongs_to :organization, :class_name => 'Users::Github::Organization'
7+
end
8+
end
9+
end
410
end
511

612
# == Schema Information

app/models/users/github/profile.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
class Users::Github::Profile < ActiveRecord::Base
2-
belongs_to :user
3-
has_many :followers, class_name: 'Users::Github::Profiles::Follower' , foreign_key: :follower_id , dependent: :delete_all
4-
has_many :repositories, :class_name => 'Users::Github::Repository' , foreign_key: :owner_id
5-
validates :login , presence: true, uniqueness: true
6-
before_validation :copy_login_from_user, on: :create
7-
after_create :extract_data_from_github
1+
module Users
2+
module Github
3+
class Profile < ActiveRecord::Base
4+
belongs_to :user
5+
has_many :followers, class_name: 'Users::Github::Profiles::Follower' , foreign_key: :follower_id , dependent: :delete_all
6+
has_many :repositories, :class_name => 'Users::Github::Repository' , foreign_key: :owner_id
7+
validates :login , presence: true, uniqueness: true
8+
before_validation :copy_login_from_user, on: :create
9+
after_create :extract_data_from_github
810

911

10-
private
12+
private
1113

12-
def copy_login_from_user
13-
self.login = user.github
14-
end
14+
def copy_login_from_user
15+
self.login = user.github
16+
end
1517

16-
def extract_data_from_github
17-
ExtractGithubProfile.perform_async(id)
18-
end
18+
def extract_data_from_github
19+
ExtractGithubProfile.perform_async(id)
20+
end
1921

22+
end
23+
end
2024
end
2125

2226
# == Schema Information

app/models/users/github/profiles.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
module Users::Github::Profiles
2-
def self.table_name_prefix
3-
'users_github_profiles_'
1+
module Users
2+
module Github
3+
module Profiles
4+
def self.table_name_prefix
5+
'users_github_profiles_'
6+
end
7+
end
48
end
59
end

app/models/users/github/profiles/follower.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
class Users::Github::Profiles::Follower < ActiveRecord::Base
2-
belongs_to :profile, :class_name => 'Users::Github::Profile'
3-
belongs_to :follower, :class_name => 'Users::Github::Profile'
1+
module Users
2+
module Github
3+
module Profiles
4+
class Follower < ActiveRecord::Base
5+
belongs_to :profile, :class_name => 'Users::Github::Profile'
6+
belongs_to :follower, :class_name => 'Users::Github::Profile'
7+
end
8+
end
9+
end
410
end
511

612
# == Schema Information
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
module Users::Github::Repositories
2-
def self.table_name_prefix
3-
'users_github_repositories_'
1+
module Users
2+
module Github
3+
module Repositories
4+
def self.table_name_prefix
5+
'users_github_repositories_'
6+
end
7+
end
48
end
59
end

app/models/users/github/repositories/contributor.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
class Users::Github::Repositories::Contributor < ActiveRecord::Base
2-
belongs_to :profile, class_name: 'Users::Github::Profile'
3-
belongs_to :repository, :class_name => 'Users::Github::Repository'
1+
module Users
2+
module Github
3+
module Repositories
4+
class Contributor < ActiveRecord::Base
5+
belongs_to :profile, class_name: 'Users::Github::Profile'
6+
belongs_to :repository, :class_name => 'Users::Github::Repository'
7+
end
8+
end
9+
end
410
end
511

612
# == Schema Information

app/models/users/github/repositories/follower.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
class Users::Github::Repositories::Follower < ActiveRecord::Base
2-
belongs_to :profile, class_name: 'Users::Github::Profile'
3-
belongs_to :repository, :class_name => 'Users::Github::Repository'
1+
module Users
2+
module Github
3+
module Repositories
4+
class Follower < ActiveRecord::Base
5+
belongs_to :profile, class_name: 'Users::Github::Profile'
6+
belongs_to :repository, :class_name => 'Users::Github::Repository'
7+
end
8+
end
9+
end
410
end
511

612
# == Schema Information

app/models/users/github/repository.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
class Users::Github::Repository < ActiveRecord::Base
2-
has_many :followers, :class_name => 'Users::Github::Repositories::Follower' , dependent: :delete_all
3-
has_many :contributors, :class_name => 'Users::Github::Repositories::Contributor' , dependent: :delete_all
4-
belongs_to :organization, :class_name => 'Users::Github::Organization'
5-
belongs_to :owner, :class_name => 'Users::Github::Profile'
1+
module Users
2+
module Github
3+
class Repository < ActiveRecord::Base
4+
has_many :followers, :class_name => 'Users::Github::Repositories::Follower' , dependent: :delete_all
5+
has_many :contributors, :class_name => 'Users::Github::Repositories::Contributor' , dependent: :delete_all
6+
belongs_to :organization, :class_name => 'Users::Github::Organization'
7+
belongs_to :owner, :class_name => 'Users::Github::Profile'
8+
end
9+
end
610
end
711

812
# == Schema Information

0 commit comments

Comments
 (0)