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
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/hubstats/repo.rb', line 96 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/hubstats/repo.rb', line 116 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
143 144 145 |
# File 'app/models/hubstats/repo.rb', line 143 def to_param self.name end |