# encoding: UTF-8

module Spontaneous
  class Facet
    def initialize(root)
      @root = root
      paths.add :lib, ["lib", "**/*.rb"]
      paths.add :schema, ["schema", "**/*.rb"]
      paths.add :templates, "templates"
      paths.add :config, "config"
      paths.add :tasks, ["lib/tasks", "**/*.rake"]
      paths.add :migrations, ["db/migrations", "**/*.rake"]
      paths.add :plugins, ["plugins", "*"]
      paths.add :features, "features"
    end

    def paths
      @paths ||= Spontaneous::Paths.new(@root)
    end

    def config
      Site.instance.config
    end

    def load_config!
      paths.expanded(:config).each do |config_path|
        Site.config.load(config_path)
      end
    end

    def load_indexes!
      paths.expanded(:config).each do |config_path|
        load(config_path / "indexes.rb" )
      end
    end

    def init!
    end

    def load!
      Spontaneous::Loader.load_classes(load_paths)
    end

    def load_paths
      load_paths = []
      [:lib, :schema].each do |category|
        load_paths += paths.expanded(category)
      end
      load_paths
    end

  end # Facet
end # Spontaneous

# encoding: UTF-8

module Spontaneous
  class Facet
    def initialize(root)
      @root = root
      paths.add :lib, ["lib", "**/*.rb"]
      paths.add :schema, ["schema", "**/*.rb"]
      paths.add :templates, "templates"
      paths.add :config, "config"
      paths.add :tasks, ["lib/tasks", "**/*.rake"]
      paths.add :migrations, ["db/migrations", "**/*.rake"]
      paths.add :plugins, ["plugins", "*"]
      paths.add :features, "features"
    end

    def paths
      @paths ||= Spontaneous::Paths.new(@root)
    end

    def config
      Site.instance.config
    end

    def load_config!
      paths.expanded(:config).each do |config_path|
        Site.config.load(config_path)
      end
    end

    def load_indexes!
      paths.expanded(:config).each do |config_path|
        index_file = config_path / "indexes.rb"
        load(index_file) if File.exists?(index_file)
      end
    end

    def init!
    end

    def load!
      Spontaneous::Loader.load_classes(load_paths)
    end

    def load_paths
      load_paths = []
      [:lib, :schema].each do |category|
        load_paths += paths.expanded(category)
      end
      load_paths
    end

  end # Facet
end # Spontaneous

Make loading of indexes.rb dependent on its existance
Make loading of indexes.rb dependent on its existance
