Class: Hubstats::Repo
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hubstats::Repo
- Defined in:
- app/models/hubstats/repo.rb
Class Method Summary collapse
-
.create_or_update(github_repo) ⇒ Object
Public - Makes a new repository based on a GitHub webhook.
-
.custom_order(order_params) ⇒ Object
Public - Designed so that the list of repositories can be ordered based on deploys, pulls, comments, additions, deletions, or name.
- .record_timestamps ⇒ Object
Instance Method Summary collapse
-
#to_param ⇒ Object
Public - Designed to make a path for the show page when a repository is selected.
Class Method Details
.create_or_update(github_repo) ⇒ Object
Public - Makes a new repository based on a GitHub webhook. Sets a user (owner) based on users that are already in the database.
github_repo - the info about the new or updated repository
Returns - the repository
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/hubstats/repo.rb', line 88 def self.create_or_update(github_repo) github_repo = github_repo.to_h.with_indifferent_access if github_repo.respond_to? :to_h repo_data = github_repo.slice(*column_names.map(&:to_sym)) if github_repo[:owner] user = Hubstats::User.create_or_update(github_repo[:owner]) repo_data[:owner_id] = user[:id] end repo = where(:id => repo_data[:id]).first_or_create(repo_data) return repo if repo.update_attributes(repo_data) Rails.logger.warn repo.errors.inspect end |
.custom_order(order_params) ⇒ Object
Public - Designed so that the list of repositories can be ordered based on deploys, pulls, comments, additions, deletions, or name. if none of these are selected, then the default is to order by pull request count in descending order.
order_params - the param of what the repos should be sorted by
Returns - the repo data ordered
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/hubstats/repo.rb', line 108 def self.custom_order(order_params) if order_params order = order_params.include?('asc') ? "ASC" : "DESC" case order_params.split('-').first when 'deploys' order("deploy_count #{order}") when 'pulls' order("pull_request_count #{order}") when 'comments' order("comment_count #{order}") when 'additions' order("average_additions #{order}") when 'deletions' order("average_deletions #{order}") when 'name' order("name #{order}") else order("pull_request_count #{order}") end else order("pull_request_count DESC") end end |
.record_timestamps ⇒ Object
4 |
# File 'app/models/hubstats/repo.rb', line 4 def self.; false; end |
Instance Method Details
#to_param ⇒ Object
Public - Designed to make a path for the show page when a repository is selected.
Returns - the show page of self.name
135 136 137 |
# File 'app/models/hubstats/repo.rb', line 135 def to_param self.name end |