<commit_before>require 'hashie/mash'
require 'erb'

module Choices
  extend self
  
  def load_settings(filename, env)
    mash = Hashie::Mash.new(load_settings_hash(filename, env))
    
    with_local_settings(filename, env, '.local') do |local|
      mash.update local
    end
    
    return mash
  end
  
  def load_settings_hash(filename, env)
    yaml_content = ERB.new(IO.read(filename)).result
    yaml_load(yaml_content)[env]
  end
  
  def with_local_settings(filename, env, suffix)
    local_filename = filename.sub(/(\.\w+)?$/, "#{suffix}\\1")
    if File.exists? local_filename
      hash = load_settings_hash(local_filename, env)
      yield hash if hash
    end
  end
  
  def yaml_load(content)
    if defined? YAML::ENGINE
      # avoid using broken Psych in 1.9.2
      old_yamler = YAML::ENGINE.yamler
      YAML::ENGINE.yamler = 'syck'
    end
    begin
      YAML::load(content)
    ensure
      YAML::ENGINE.yamler = old_yamler if defined? YAML::ENGINE
    end
  end
end

if defined? Rails
  require 'choices/rails'
end<commit_msg>don't try to use Syck in Ruby 2.0<commit_after>require 'hashie/mash'
require 'erb'

module Choices
  extend self
  
  def load_settings(filename, env)
    mash = Hashie::Mash.new(load_settings_hash(filename, env))
    
    with_local_settings(filename, env, '.local') do |local|
      mash.update local
    end
    
    return mash
  end
  
  def load_settings_hash(filename, env)
    yaml_content = ERB.new(IO.read(filename)).result
    yaml_load(yaml_content)[env]
  end
  
  def with_local_settings(filename, env, suffix)
    local_filename = filename.sub(/(\.\w+)?$/, "#{suffix}\\1")
    if File.exists? local_filename
      hash = load_settings_hash(local_filename, env)
      yield hash if hash
    end
  end
  
  def yaml_load(content)
    if defined?(YAML::ENGINE) && defined?(Syck)
      # avoid using broken Psych in 1.9.2
      old_yamler = YAML::ENGINE.yamler
      YAML::ENGINE.yamler = 'syck'
    end
    begin
      YAML::load(content)
    ensure
      YAML::ENGINE.yamler = old_yamler if defined?(YAML::ENGINE) && defined?(Syck)
    end
  end
end

if defined? Rails
  require 'choices/rails'
end
{'fraction_non_alphanumeric': 0.10905730129390019, 'fraction_numerical': 0.0046210720887245845, 'mean_word_length': 3.0619136960600377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '601689', 'n_tokens_mistral': 802, 'n_tokens_neox': 765, 'n_words': 174}