<commit_before>class Artifact < ActiveRecord::Base
  
  belongs_to :portfolio
  
  has_many :pictures,  -> { order(position: :asc) },  dependent: :destroy, as: :resource
  
  acts_as_taggable_on :category, :department

  def action_viewer
    
    return (artifact_action_viewer.blank? ? "artifact_detail" : artifact_action_viewer) rescue "artifact_detail"
    
  end
  
  def next_in_portfolio 
    artifact_list = self.portfolio.artifacts.where(:artifact_active=>1).order(:position)
     if artifact_list.length <= 1 then
      return self
    end
    artifact_list.index(self)
    if artifact_list.last == self then
      return artifact_list.first
    else
      return artifact_list[artifact_list.index(self) + 1 ]
    end
  end
  
  def previous_in_portfolio
    artifact_list =  self.portfolio.artifacts.where(:artifact_active=>1).order(:position)
    
    if artifact_list.null? or artifact_list.length <= 1 then
      return self
    end
    
    
    artifact_list.index(self)
    
    if artifact_list.first == self then
      return artifact_list.last
    else
      return artifact_list[artifact_list.index(self) - 1 ] rescue self
    end
  end
  
end<commit_msg>Fixed issue where prev next would fail because current artifiact is not activated.<commit_after>class Artifact < ActiveRecord::Base
  
  belongs_to :portfolio
  
  has_many :pictures,  -> { order(position: :asc) },  dependent: :destroy, as: :resource
  
  acts_as_taggable_on :category, :department

  def action_viewer
    
    return (artifact_action_viewer.blank? ? "artifact_detail" : artifact_action_viewer) rescue "artifact_detail"
    
  end
  
  def next_in_portfolio 
    artifact_list = self.portfolio.artifacts.where(:artifact_active=>1).order(:position)
     if artifact_list.length <= 1 then
      return self
    end
    artifact_list.index(self)
    if artifact_list.last == self then
      return artifact_list.first
    else
      return artifact_list[artifact_list.index(self) + 1 ]
    end
  end
  
  def previous_in_portfolio
    artifact_list =  self.portfolio.artifacts.where(:artifact_active=>1).order(:position)
    
    if artifact_list.empty? or artifact_list.length <= 1 then
      return self
    end
    
    
    artifact_list.index(self)
    
    if artifact_list.first == self then
      return artifact_list.last
    else
      return artifact_list[artifact_list.index(self) - 1 ] rescue self
    end
  end
  
end
{'fraction_non_alphanumeric': 0.0796862097440132, 'fraction_numerical': 0.00495458298926507, 'mean_word_length': 3.1775862068965517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '773343', 'n_tokens_mistral': 810, 'n_tokens_neox': 752, 'n_words': 167}