<commit_before>class FeatureStatus < ActiveRecord::Base
  has_many :features

  before_create :check_and_update_default_status, :set_next_position
  before_update :check_and_update_default_status

  def set_next_position
    last_status = FeatureStatus.find(:last, :order => "position")

    unless last_status.nil?
      self.position = last_status.position + 1
    end
  end

  def check_and_update_default_status
    default = FeatureStatus.default_status

    unless default.nil?
      if self.default_status and not @bypass
        # Change the current default status to make sure there's only one default status
        default.default_status = false
        default.save
      end
    end
  end

  def update_position(direction)
    position = self.position

    if direction.eql? 'up'
      status = FeatureStatus.find_by_position(position.to_i - 1)
    else
      status = FeatureStatus.find_by_position(position.to_i + 1)
    end
    
    self.position = status.position
    status.position = position

    FeatureStatus.transaction do
      @bypass = true
      self.save
      status.save
    end

    return self
  end

  # Class methods
  class << self

    def default_status
      FeatureStatus.first(:conditions => {:default_status => true})
    end<commit_msg>Default status stays during update position<commit_after>class FeatureStatus < ActiveRecord::Base
  has_many :features

  before_create :check_and_update_default_status, :set_next_position
  before_update :check_and_update_default_status

  def set_next_position
    last_status = FeatureStatus.find(:last, :order => "position")

    unless last_status.nil?
      self.position = last_status.position + 1
    end
  end

  def check_and_update_default_status
    default = FeatureStatus.default_status

    unless default.nil?
      if self.default_status and not @@bypass
        # Change the current default status to make sure there's only one default status
        default.default_status = false
        default.save
      end
    end
  end

  def update_position(direction)
    position = self.position

    if direction.eql? 'up'
      status = FeatureStatus.find_by_position(position.to_i - 1)
    else
      status = FeatureStatus.find_by_position(position.to_i + 1)
    end
    
    self.position = status.position
    status.position = position

    @@bypass = true

    if self.position.eql? 1
      self.default_status = true
      default = FeatureStatus.default_status
      default.default_status = false
      default.save
    end

    FeatureStatus.transaction do
      self.save
      status.save
    end

    return self
  end

  # Class methods
  class << self

    def default_status
      FeatureStatus.first(:conditions => {:default_status => true})
    end
{'fraction_non_alphanumeric': 0.06453952139231327, 'fraction_numerical': 0.0025380710659898475, 'mean_word_length': 2.9755043227665707, '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': '7220580', 'n_tokens_mistral': 808, 'n_tokens_neox': 770, 'n_words': 199}