AutoRest.ar_require_relative __FILE__, 'configuration', 'main.rb'

AutoRest.ar_require_relative __FILE__, 'application_helpers', 'application_helper_methods.rb'

AutoRest.ar_require_relative __FILE__, 'instance_methods', 'for_model_manipulation'
AutoRest.ar_require_relative __FILE__, 'instance_methods', 'for_miscelaneous' 

AutoRest.ar_require_relative __FILE__, 'breadcrumbs', 'breadcrumbs_class_methods.rb'
AutoRest.ar_require_relative __FILE__, 'breadcrumbs', 'breadcrumbs_helpers.rb'

module AutoRest
  module RestClassMethods
    
    include AutoRest::Configuration 
    
    private
    
    # Main auto_rest configuration and creation class method for ActionController::Base
    # The parameter module_underscored allows the usage of different implementation
    # of the default methods for the controller. 
    # For seeing the implementation, browse /lib/auto_rest/default_methods once generated 
    # the "scaffold" by ruby script/generate ar_spec_scaffold ResName
    def create_auto_rest module_underscored= "auto_rest/default_methods"
      options= prepare_options_container()
      
      yield options if block_given?
      
      # Each class will get it's ardata method with different data
      data= proccess_options_container options
      
      write_inheritable_attribute :ardata, data
      class_inheritable_reader    :ardata
      helper_method :ardata
      
      master_helper_module.send :include, AutoRest::BreadcrumbsHelpers

      include AutoRest::RestInstanceMethods::ModelManipulation
      include AutoRest::RestInstanceMethods::Miscelaneous
      
      # Include default REST methods into the controller
      data.methods.each do |method|
        include "#{module_underscored}/#{method.to_s}".camelize.constantize
      end
    end
    
  end #module RestClassMethods
end #module AutoRest  

ActionController::Base.extend AutoRest::RestClassMethods