-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infrastructure holds database and github
- Loading branch information
Showing
30 changed files
with
225 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'hirb' | ||
|
||
Hirb.enable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
development: | ||
db_filename: infrastructure/db/dev.db | ||
db_filename: infrastructure/database/dev.db | ||
|
||
test: | ||
db_filename: infrastructure/db/test.db | ||
db_filename: infrastructure/database/test.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Repository | ||
# Repository for Collaborators | ||
class Collaborators | ||
def self.find_id(id) | ||
db_record = Database::CollaboratorOrm.first(id: id) | ||
rebuild_entity(db_record) | ||
end | ||
|
||
def self.find_username(username) | ||
db_record = Database::CollaboratorOrm.first(username: username) | ||
rebuild_entity(db_record) | ||
end | ||
|
||
def self.find_or_create(entity) | ||
find_username(entity.username) || create_from(entity) | ||
end | ||
|
||
def self.create_from(entity) | ||
db_collaborator = Database::CollaboratorOrm.create( | ||
origin_id: entity.origin_id, | ||
username: entity.username, | ||
email: entity.email | ||
) | ||
|
||
self.rebuild_entity(db_collaborator) | ||
end | ||
|
||
def self.rebuild_entity(db_record) | ||
return nil unless db_record | ||
|
||
Entity::Collaborator.new( | ||
id: db_record.id, | ||
origin_id: db_record.origin_id, | ||
username: db_record.username, | ||
email: db_record.email | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Repository | ||
For = { | ||
Entity::Repo => Repos, | ||
Entity::Collaborator => Collaborators | ||
}.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'repos.rb' | ||
require_relative 'collaborators.rb' | ||
require_relative 'for.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Repository | ||
# Repository for Repo Entities | ||
class Repos | ||
def self.find_full_name(ownername, reponame) | ||
# SELECT * FROM `repos` LEFT JOIN `collaborators` | ||
# ON (`collaborators`.`id` = `repos`.`owner_id`) | ||
# WHERE ((`username` = 'owername') AND (`name` = 'reponame')) | ||
db_repo = Database::RepoOrm.left_join(:collaborators, id: :owner_id) | ||
.where(username: ownername, name: reponame) | ||
.first | ||
rebuild_entity(db_repo) | ||
end | ||
|
||
def self.find_id(id) | ||
Database::RepoOrm.first(id: id)&.rebuild_entity | ||
end | ||
|
||
def self.find_origin_id(origin_id) | ||
db_record = Database::RepoOrm.first(origin_id: origin_id) | ||
rebuild_entity(db_record) | ||
end | ||
|
||
def self.find_or_create(entity) | ||
find_origin_id(entity.origin_id) || create_from(entity) | ||
end | ||
|
||
def self.create_from(entity) | ||
new_owner = Collaborators.find_or_create(entity.owner) | ||
db_owner = Database::CollaboratorOrm.first(id: new_owner.id) | ||
|
||
db_repo = Database::RepoOrm.create( | ||
origin_id: entity.origin_id, | ||
name: entity.name, | ||
size: entity.size, | ||
git_url: entity.git_url, | ||
owner: db_owner | ||
) | ||
|
||
entity.contributors.each do |contrib| | ||
stored_contrib = Collaborators.find_or_create(contrib) | ||
contrib = Database::CollaboratorOrm.first(id: stored_contrib.id) | ||
db_repo.add_contributor(contrib) | ||
end | ||
|
||
rebuild_entity(db_repo) | ||
end | ||
|
||
def self.rebuild_entity(db_record) | ||
return nil unless db_record | ||
|
||
contribs = db_record.contributors.map do |db_contrib| | ||
Collaborators.rebuild_entity(db_contrib) | ||
end | ||
|
||
Entity::Repo.new( | ||
id: db_record.id, | ||
origin_id: db_record.origin_id, | ||
name: db_record.name, | ||
size: db_record.size, | ||
git_url: db_record.git_url, | ||
owner: Collaborators.rebuild_entity(db_record.owner), | ||
contributors: contribs | ||
) | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
folders = %w[entities database_repositories github_mappers] | ||
folders.each do |folder| | ||
require_relative "#{folder}/init.rb" | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Database | ||
# Object-Relational Mapper for Collaborators | ||
class CollaboratorOrm < Sequel::Model(:collaborators) | ||
one_to_many :owned_repos, | ||
class: :'CodePraise::Database::RepoOrm', | ||
key: :owner_id | ||
|
||
many_to_many :contributed_repos, | ||
join_table: :repos_contributors, | ||
left_key: :contributor_id, right_key: :repo_id | ||
|
||
plugin :timestamps, update_on_create: true | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# # frozen_string_literal: true | ||
|
||
# module CodePraise | ||
# module Database | ||
# ORM = { | ||
# CodePraise::Entity::Repo => RepoOrm, | ||
# CodePraise::Entity::Collaborator => CollaboratorOrm | ||
# }.freeze | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Database | ||
# Object Relational Mapper for Repo Entities | ||
class RepoOrm < Sequel::Model(:repos) | ||
many_to_one :owner, | ||
class: :'CodePraise::Database::CollaboratorOrm' | ||
|
||
many_to_many :contributors, | ||
class: :'CodePraise::Database::CollaboratorOrm', | ||
join_table: :repos_contributors, | ||
left_key: :repo_id, right_key: :collaborator_id | ||
|
||
plugin :timestamps, update_on_create: true | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# frozen_string_literal: false | ||
|
||
require_relative 'github_api.rb' | ||
require_relative 'mappers/init.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# frozen_string_literal: false | ||
|
||
require_relative 'db/orm/init.rb' | ||
folders = %w[github database/orm] | ||
folders.each do |folder| | ||
require_relative "#{folder}/init.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.