Class: Writefully::Authorship

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/writefully/authorship.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_data(auth_user) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/writefully/authorship.rb', line 24

def self.create_from_data(auth_user)
  create! do |authorship|
    authorship.data = { email: auth_user.email,
                        uid: auth_user.id,
                        user_name: auth_user.,
                        name: auth_user.name,
                        avatar: auth_user.avatar_url }.select { |k,v| v.present? }
                        
    authorship.role = authorship.select_role
  end 
end

.find_by_uid(uid) ⇒ Object



16
17
18
# File 'app/models/writefully/authorship.rb', line 16

def self.find_by_uid(uid)
  where("data -> 'uid' = ?", uid.to_s).first
end

Instance Method Details

#select_roleObject



20
21
22
# File 'app/models/writefully/authorship.rb', line 20

def select_role
  Authorship.count == 0 ? "super_admin" : "collaborator"
end

#to_sObject



12
13
14
# File 'app/models/writefully/authorship.rb', line 12

def to_s
  data["name"] || data["login"] || data["email"] || data["uid"]
end