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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/hubstats/repo.rb', line 17

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

Instance Method Details

#to_paramObject



31
32
33
# File 'app/models/hubstats/repo.rb', line 31

def to_param
  self.name
end