<commit_before>class ServerRole < ActiveRecord::Base
  has_many :assigned_server_roles
  has_many :miq_servers, :through => :assigned_server_roles

  validates_presence_of     :name
  validates_uniqueness_of   :name

  FIXTURE_DIR = File.join(Rails.root, "db/fixtures")

  def self.seed_data
    File.read(File.join(FIXTURE_DIR, "#{self.to_s.pluralize.underscore}.csv"))
  end

  def self.seed
    MiqRegion.my_region.lock do
      data = self.seed_data.split("\n")
      cols = data.shift.split(",")

      data.each do |a|
        next if a =~ /^#.*$/ # skip commented lines

        arr = a.split(",")

        action = {}
        cols.each_index {|i| action[cols[i].to_sym] = arr[i]}

        rec = self.where(:name => (action[:name])).first
        if rec.nil?
          $log.info("MIQ(ServerRole.seed) Creating Server Role [#{action[:name]}]")
          rec = self.create(action)
        else
          rec.attributes = action
          if rec.changed?
            $log.info("MIQ(ServerRole.seed) Updating Server Role [#{action[:name]}]")
            rec.save
          end
        end
      end
    end
    @zone_scoped_roles = @region_scoped_roles = nil
  end

  def self.to_role(server_role)
    # server_role can either be a Role Name (string or symbol) or an instance of a ServerRole
    unless server_role.kind_of?(ServerRole)
      role_name   = server_role.to_s.strip.downcase
      server_role = ServerRole.where(:name => role_name).first
      raise "Role <#{role_name}> not defined in server_roles table" if server_role.nil?
    end

    server_role
  end

  def self.all_names
    self.order(:name).pluck(:name)
  end

  def self.database_scoped_role_names
    self.where(:role_scope => 'database').order(:name).pluck(:name)
  end

  def self.database_scoped_roles
    @database_scoped_roles ||= self.where(:role_scope => ('database').order(:name))
  end

  def self.region_scoped_roles
    @region_scoped_roles ||= self.where(:role_scope => 'region').order(:name)
  end

  def self.zone_scoped_roles
    @zone_scoped_roles ||= self.where(:role_scope => 'zone').order(:name)
  end

  def self.database_role?(role)
    self.database_scoped_roles.any? {|r| r.name == role.to_s}
  end<commit_msg>Make these ivars arrays<commit_after>class ServerRole < ActiveRecord::Base
  has_many :assigned_server_roles
  has_many :miq_servers, :through => :assigned_server_roles

  validates_presence_of     :name
  validates_uniqueness_of   :name

  FIXTURE_DIR = File.join(Rails.root, "db/fixtures")

  def self.seed_data
    File.read(File.join(FIXTURE_DIR, "#{self.to_s.pluralize.underscore}.csv"))
  end

  def self.seed
    MiqRegion.my_region.lock do
      data = self.seed_data.split("\n")
      cols = data.shift.split(",")

      data.each do |a|
        next if a =~ /^#.*$/ # skip commented lines

        arr = a.split(",")

        action = {}
        cols.each_index {|i| action[cols[i].to_sym] = arr[i]}

        rec = self.where(:name => (action[:name])).first
        if rec.nil?
          $log.info("MIQ(ServerRole.seed) Creating Server Role [#{action[:name]}]")
          rec = self.create(action)
        else
          rec.attributes = action
          if rec.changed?
            $log.info("MIQ(ServerRole.seed) Updating Server Role [#{action[:name]}]")
            rec.save
          end
        end
      end
    end
    @zone_scoped_roles = @region_scoped_roles = nil
  end

  def self.to_role(server_role)
    # server_role can either be a Role Name (string or symbol) or an instance of a ServerRole
    unless server_role.kind_of?(ServerRole)
      role_name   = server_role.to_s.strip.downcase
      server_role = ServerRole.where(:name => role_name).first
      raise "Role <#{role_name}> not defined in server_roles table" if server_role.nil?
    end

    server_role
  end

  def self.all_names
    self.order(:name).pluck(:name)
  end

  def self.database_scoped_role_names
    self.where(:role_scope => 'database').order(:name).pluck(:name)
  end

  def self.database_scoped_roles
    @database_scoped_roles ||= self.where(:role_scope => 'database').order(:name).to_a
  end

  def self.region_scoped_roles
    @region_scoped_roles ||= self.where(:role_scope => 'region').order(:name).to_a
  end

  def self.zone_scoped_roles
    @zone_scoped_roles ||= self.where(:role_scope => 'zone').order(:name).to_a
  end

  def self.database_role?(role)
    self.database_scoped_roles.any? {|r| r.name == role.to_s}
  end
{'fraction_non_alphanumeric': 0.12755905511811025, 'fraction_numerical': 0.0, 'mean_word_length': 3.030825022665458, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '3843427', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1529, 'n_words': 298}