Class: Hubstats::Repo

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hubstats/repo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_or_update(github_repo) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/hubstats/repo.rb', line 59

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/hubstats/repo.rb', line 73

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

Instance Method Details

#to_paramObject



97
98
99
# File 'app/models/hubstats/repo.rb', line 97

def to_param
  self.name
end