<commit_before>require 'with_advisory_lock'
require 'closure_tree/support'
require 'closure_tree/hierarchy_maintenance'
require 'closure_tree/model'
require 'closure_tree/finders'
require 'closure_tree/hash_tree'
require 'closure_tree/digraphs'
require 'closure_tree/deterministic_ordering'
require 'closure_tree/numeric_deterministic_ordering'

module ClosureTree
  module ActsAsTree
    def acts_as_tree(options = {})
      class_attribute :_ct
      self._ct = ClosureTree::Support.new(self, options)

      # Auto-inject the hierarchy table
      # See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
      class_attribute :hierarchy_class
      self.hierarchy_class = _ct.hierarchy_class_for_model

      # tests fail if you include Model before HierarchyMaintenance wtf
      include ClosureTree::HierarchyMaintenance
      include ClosureTree::Model
      include ClosureTree::Finders
      include ClosureTree::HashTree
      include ClosureTree::Digraphs

      include ClosureTree::DeterministicOrdering if _ct.order_option?
      include ClosureTree::NumericDeterministicOrdering if _ct.order_is_numeric?
    end
  end
end<commit_msg>add rescue if db is not available<commit_after>require 'with_advisory_lock'
require 'closure_tree/support'
require 'closure_tree/hierarchy_maintenance'
require 'closure_tree/model'
require 'closure_tree/finders'
require 'closure_tree/hash_tree'
require 'closure_tree/digraphs'
require 'closure_tree/deterministic_ordering'
require 'closure_tree/numeric_deterministic_ordering'

module ClosureTree
  module ActsAsTree
    def acts_as_tree(options = {})
      class_attribute :_ct
      self._ct = ClosureTree::Support.new(self, options)

      # Auto-inject the hierarchy table
      # See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
      class_attribute :hierarchy_class
      self.hierarchy_class = _ct.hierarchy_class_for_model

      # tests fail if you include Model before HierarchyMaintenance wtf
      include ClosureTree::HierarchyMaintenance
      include ClosureTree::Model
      include ClosureTree::Finders
      include ClosureTree::HashTree
      include ClosureTree::Digraphs

      include ClosureTree::DeterministicOrdering if _ct.order_option?
      include ClosureTree::NumericDeterministicOrdering if _ct.order_is_numeric?
    rescue ActiveRecord::ConnectionNotEstablished => e
      # Support for heroku's database-less assets:precompile step:
      ActiveRecord::Base.logger.warn("Database connection could not be established. Are we doing an assets:precompile?")
      ActiveRecord::Base.logger.warn(ENV.map{|k,v| "#{k} => #{v}"}.join("\n"))
    end
  end
end
{'fraction_non_alphanumeric': 0.07703595011005136, 'fraction_numerical': 0.0, 'mean_word_length': 4.851931330472103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4310651', 'n_tokens_mistral': 843, 'n_tokens_neox': 803, 'n_words': 166}