<commit_before># == Schema Information
#
# Table name: registry_entries
#
#  id          :integer         not null, primary key
#  env         :string(255)
#  parent_id   :integer
#  key         :string(255)
#  type        :string(255)
#  value       :string(255)
#  label       :string(255)
#  description :string(255)
#  user_id     :integer
#  created_at  :datetime
#  updated_at  :datetime
#  version     :integer
#  notes       :text
#
# Indexes
#
#  index_registry_entries_on_parent_id_and_key      (parent_id, key)
#

require 'registry'
require File.expand_path(File.dirname(__FILE__) + '/../../../vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned')

module Registry
  class Entry < ActiveRecord::Base

    acts_as_versioned :table_name => 'registry_entry_versions'

    set_table_name :registry_entries

    belongs_to :parent,     :class_name => 'Entry', :foreign_key => 'parent_id'
    has_many   :children,   :class_name => 'Entry', :foreign_key => 'parent_id', :order => 'key asc', :dependent => :destroy

    before_save :ensure_env
    before_save :normalize_key
    before_save :normalize_value
    after_update :clear_cache

    before_destroy :log_deletion

    ROOT_ACCESS_KEY      = 'root'
    ROOT_LABEL           = 'Configuration Schema'
    DEFAULT_YML_LOCATION = "#{Rails.root}/config/registry.yml"

    def self.environments
      connection.select_values("SELECT DISTINCT env FROM #{table_name} WHERE parent_id IS NULL")
    end

    def self.export!(file_path = DEFAULT_YML_LOCATION)
      yaml_data = {}

      environments.each do |env|
        yaml_data[env] = {}
        root(env).export(yaml_data[env])
      end

      if file_path
        File.open(file_path, 'w' ) do |out|<commit_msg>clear_cache after_save instead of after_update.<commit_after># == Schema Information
#
# Table name: registry_entries
#
#  id          :integer         not null, primary key
#  env         :string(255)
#  parent_id   :integer
#  key         :string(255)
#  type        :string(255)
#  value       :string(255)
#  label       :string(255)
#  description :string(255)
#  user_id     :integer
#  created_at  :datetime
#  updated_at  :datetime
#  version     :integer
#  notes       :text
#
# Indexes
#
#  index_registry_entries_on_parent_id_and_key      (parent_id, key)
#

require 'registry'
require File.expand_path(File.dirname(__FILE__) + '/../../../vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned')

module Registry
  class Entry < ActiveRecord::Base

    acts_as_versioned :table_name => 'registry_entry_versions'

    set_table_name :registry_entries

    belongs_to :parent,     :class_name => 'Entry', :foreign_key => 'parent_id'
    has_many   :children,   :class_name => 'Entry', :foreign_key => 'parent_id', :order => 'key asc', :dependent => :destroy

    before_save :ensure_env
    before_save :normalize_key
    before_save :normalize_value

    # after_update caused intermittent cache clearing
    after_save  :clear_cache

    before_destroy :log_deletion

    ROOT_ACCESS_KEY      = 'root'
    ROOT_LABEL           = 'Configuration Schema'
    DEFAULT_YML_LOCATION = "#{Rails.root}/config/registry.yml"

    def self.environments
      connection.select_values("SELECT DISTINCT env FROM #{table_name} WHERE parent_id IS NULL")
    end

    def self.export!(file_path = DEFAULT_YML_LOCATION)
      yaml_data = {}

      environments.each do |env|
        yaml_data[env] = {}
        root(env).export(yaml_data[env])
      end

      if file_path
        File.open(file_path, 'w' ) do |out|
{'fraction_non_alphanumeric': 0.10886644219977554, 'fraction_numerical': 0.011784511784511785, 'mean_word_length': 3.0977011494252875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6931733', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1152, 'n_words': 242}