Module: Skytapify::ActsAsSkytapUser::LocalInstanceMethods

Defined in:
lib/skytapify/acts_as_skytap_user.rb

Instance Method Summary collapse

Instance Method Details

#clear_project_ids_if_new_userObject



25
26
27
# File 'lib/skytapify/acts_as_skytap_user.rb', line 25

def clear_project_ids_if_new_user
 self.assign_attributes(project_ids: '') if skytap_id_changed?   
end

#find_or_create_skytap_userObject



18
19
20
21
22
# File 'lib/skytapify/acts_as_skytap_user.rb', line 18

def find_or_create_skytap_user
  skytap_user = api_call(organization, "user index").detect {|u| [self.email, "inactive_#{self.email}"].include?(u['email'])}
  skytap_user ||= create_skytap_user
  self.update_column(:skytap_id, skytap_user['id'])
end

#set_project_idsObject



29
30
31
32
33
34
# File 'lib/skytapify/acts_as_skytap_user.rb', line 29

def set_project_ids
 new_ids = api_call(organization, "user show #{skytap_id}/projects").map {|p| p['project']['id']}.flatten.uniq
 existing_ids = project_ids.split(',').map {|p| p.strip}
 matched_ids = existing_ids.any? ? new_ids & existing_ids : new_ids
 self.update_column(:project_ids, matched_ids.join(', '))
end

#templatesObject



36
37
38
# File 'lib/skytapify/acts_as_skytap_user.rb', line 36

def templates
  project_ids.split(',').map {|p| api_call(organization, "project show #{p.strip}/templates")}.flatten.uniq
end