<commit_before>#######################################################################################################
# Substantial portions of this code were adapted from the Radiant CMS project (http://radiantcms.org) #
#######################################################################################################
require 'spree/extension'
require 'method_observer'

module Spree
  class ExtensionLoader
    
    class DependenciesObserver < MethodObserver
      attr_accessor :config
      
      def initialize(rails_config)
        @config = rails_config
      end
      
      def after_clear(*args)
        ExtensionLoader.load_extensions
        ExtensionLoader.activate_extensions
      end
    end

    include Simpleton
    
    attr_accessor :initializer, :extensions
    
    def initialize
      self.extensions = []
    end
    
    def configuration
      initializer.configuration
    end
    
    def extension_load_paths
      load_extension_roots.map { |extension| load_paths_for(extension) }.flatten
    end

    def plugin_paths
      load_extension_roots.map {|extension| "#{extension}/vendor/plugins" }.select {|d| File.directory?(d) }
    end
    
    def add_extension_paths
      extension_load_paths.reverse_each do |path|
        configuration.load_paths.unshift path
        $LOAD_PATH.unshift path
      end
    end
    
    def add_plugin_paths
      configuration.plugin_paths.concat plugin_paths
    end

    def controller_paths
      extensions.map { |extension| "#{extension.root}/app/controllers" }.select { |d| File.directory?(d) }
    end
    
    def add_controller_paths
      configuration.controller_paths.concat(controller_paths)
    end
    
    def view_paths
      extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }
    end
    
    # Load the extensions
    def load_extensions
      @observer ||= DependenciesObserver.new(configuration).observe(::Dependencies)
      self.extensions = load_extension_roots.map do |root|
        begin
          extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"       
          extension = extension_file.camelize.constantize
          extension.unloadable
          extension.root = root
          extension
        rescue LoadError, NameError => e
          $stderr.puts "Could not load extension from file: #{extension_file}.\n#{e.inspect}"
          nil
        end
      end.compact
    end
    
    def activate_extensions
#      initializer.initialize_default_admin_tabs
      # Reset the view paths after 
      initializer.initialize_framework_views
      extensions.each &:activate
    end<commit_msg>Fixed deprecation warnings for Dependencies (use ActiveSupport::Dependencies instead) #141.<commit_after>#######################################################################################################
# Substantial portions of this code were adapted from the Radiant CMS project (http://radiantcms.org) #
#######################################################################################################
require 'spree/extension'
require 'method_observer'

module Spree
  class ExtensionLoader
    
    class DependenciesObserver < MethodObserver
      attr_accessor :config
      
      def initialize(rails_config)
        @config = rails_config
      end
      
      def after_clear(*args)
        ExtensionLoader.load_extensions
        ExtensionLoader.activate_extensions
      end
    end

    include Simpleton
    
    attr_accessor :initializer, :extensions
    
    def initialize
      self.extensions = []
    end
    
    def configuration
      initializer.configuration
    end
    
    def extension_load_paths
      load_extension_roots.map { |extension| load_paths_for(extension) }.flatten
    end

    def plugin_paths
      load_extension_roots.map {|extension| "#{extension}/vendor/plugins" }.select {|d| File.directory?(d) }
    end
    
    def add_extension_paths
      extension_load_paths.reverse_each do |path|
        configuration.load_paths.unshift path
        $LOAD_PATH.unshift path
      end
    end
    
    def add_plugin_paths
      configuration.plugin_paths.concat plugin_paths
    end

    def controller_paths
      extensions.map { |extension| "#{extension.root}/app/controllers" }.select { |d| File.directory?(d) }
    end
    
    def add_controller_paths
      configuration.controller_paths.concat(controller_paths)
    end
    
    def view_paths
      extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }
    end
    
    # Load the extensions
    def load_extensions
      @observer ||= DependenciesObserver.new(configuration).observe(ActiveSupport::Dependencies)
      self.extensions = load_extension_roots.map do |root|
        begin
          extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"       
          extension = extension_file.camelize.constantize
          extension.unloadable
          extension.root = root
          extension
        rescue LoadError, NameError => e
          $stderr.puts "Could not load extension from file: #{extension_file}.\n#{e.inspect}"
          nil
        end
      end.compact
    end
    
    def activate_extensions
#      initializer.initialize_default_admin_tabs
      # Reset the view paths after 
      initializer.initialize_framework_views
      extensions.each &:activate
    end
{'fraction_non_alphanumeric': 0.14709677419354839, 'fraction_numerical': 0.0005529953917050691, 'mean_word_length': 2.914862914862915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5874228', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1390, 'n_words': 313}