# The module containing all the code for make_resourceful.
#
# For methods available in the +make_resourceful+ block,
# see Resourceful::Builder.
#
# For helper methods and methods you can override
# to customize the behavior of your actions,
# see Resourceful::Default::Accessors
# and Resourceful::Default::URLs.
module Resourceful
  # We want to define some stuff before we load other modules

  # The default actions generated by make_resourceful.
  ACTIONS = [:index, :show, :edit, :update, :create, :new, :destroy]

  # The actions that modify the database.
  MODIFYING_ACTIONS = [:update, :create, :destroy]

  # The actions that act on multiple records.
  PLURAL_ACTIONS = [:index]

  # The actions that act on just one record.
  SINGULAR_ACTIONS = ACTIONS - PLURAL_ACTIONS

  # The actions that act on just one record.
  SINGULAR_PRELOADED_ACTIONS = SINGULAR_ACTIONS - [:new, :create]
end

require 'resourceful/default/accessors'
require 'resourceful/default/responses'
require 'resourceful/default/callbacks'
require 'resourceful/default/urls'

# All modules included by this module
# are made available to the controller as accessors.
module Resourceful::Base
  @@made_resourceful_callbacks = []

  # This method is meant to be called by included classes.
  # It takes a block of the same form as that given to Maker#make_resourceful.
  # The Maker will then run that block
  # along with the blocks given by the individual controllers.
  def self.made_resourceful(&block)
    if block
      @@made_resourceful_callbacks << block
    else
      @@made_resourceful_callbacks
    end
  end

  include Resourceful::Default::Accessors
  include Resourceful::Default::Responses
  include Resourceful::Default::Callbacks
  include Resourceful::Default::URLs

  # FIXME HACK
  # making methods assigned to controller private
  # prevents access from dispatcher.
  private *Resourceful::Default::Accessors.public_instance_methods
  private *Resourceful::Default::Responses.public_instance_methods
  private *Resourceful::Default::Callbacks.public_instance_methods
  private *Resourceful::Default::URLs.public_instance_methods
end
