Module: Resourceful::Maker
- Defined in:
- lib/vendor/plugins/make_resourceful/lib/resourceful/maker.rb
Overview
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.
Class Method Summary collapse
-
.extended(base) ⇒ Object
Called automatically on ActionController::Base.
Instance Method Summary collapse
-
#made_resourceful? ⇒ Boolean
Returns whether or not make_resourceful has been called on this controller or any controllers it inherits from.
-
#make_resourceful(options = {}, &block) ⇒ Object
:call-seq: make_resourceful(options = {}) { … }.
Class Method Details
.extended(base) ⇒ Object
Called automatically on ActionController::Base. Initializes various inheritable attributes.
11 12 13 14 15 16 |
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/maker.rb', line 11 def self.extended(base) base.write_inheritable_attribute :resourceful_callbacks, {} base.write_inheritable_attribute :resourceful_responses, {} base.write_inheritable_attribute :parents, [] base.write_inheritable_attribute :made_resourceful, false end |
Instance Method Details
#made_resourceful? ⇒ Boolean
Returns whether or not make_resourceful has been called on this controller or any controllers it inherits from.
68 69 70 |
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/maker.rb', line 68 def made_resourceful? read_inheritable_attribute(:made_resourceful) end |
#make_resourceful(options = {}, &block) ⇒ Object
:call-seq:
make_resourceful(options = {}) { ... }
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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vendor/plugins/make_resourceful/lib/resourceful/maker.rb', line 49 def make_resourceful( = {}, &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([:include]).each { |proc| builder.instance_eval(&proc) } builder.instance_eval(&block) builder.apply add_helpers end |