module Resourceful::Maker
This module is extended by the ActionController::Base class object. It provides the actual make_resourceful
method and sets up the controller so that everything will work.
Public Class Methods
Called automatically on ActionController::Base. Initializes various inheritable attributes.
# File lib/resourceful/maker.rb, line 11 def self.extended(base) base.class_attribute :resourceful_callbacks base.class_attribute :resourceful_responses base.class_attribute :parents base.class_attribute :made_resourceful base.resourceful_callbacks = {} base.resourceful_responses = {} base.parents = [] base.made_resourceful = false end
Public Instance Methods
Returns whether or not make_resourceful
has been called on this controller or any controllers it inherits from.
# File lib/resourceful/maker.rb, line 73 def made_resourceful? self.class.made_resourceful end
This is the central method, and namesake, of make_resourceful. It takes a block and evaluates it in the context of a Builder
, allowing the controller to be customized extensively.
See Resourceful::Builder
for documentation on the methods available in the context of the block.
The only option currently available is :include
. It takes an object that responds to to_proc (or an array of such objects) and evaluates that proc in the same context as the block. For example:
make_resourceful :include => proc { actions :all } do before :show do current_object.current_user = current_user end end
This is the same as:
make_resourceful do actions :all before :show do current_object.current_user = current_user end end
# File lib/resourceful/maker.rb, line 54 def make_resourceful(options = {}, &block) # :stopdoc: include Resourceful::Base # :startdoc: builder = Resourceful::Builder.new(self) unless builder.inherited? Resourceful::Base.made_resourceful.each { |proc| builder.instance_eval(&proc) } end Array(options[:include]).each { |proc| builder.instance_eval(&proc) } builder.instance_eval(&block) builder.apply add_helpers end
Private Instance Methods
# File lib/resourceful/maker.rb, line 79 def add_helpers helper_method(:object_path, :objects_path, :new_object_path, :edit_object_path, :object_url, :objects_url, :new_object_url, :edit_object_url, :parent_path, :parent_url, :nested_object_path, :nested_object_url, :current_objects, :current_object, :current_model, :current_model_name, :namespaces, :instance_variable_name, :parent_names, :parent_name, :parent?, :parent_model, :parent_object, :save_succeeded?) end