Module: Resourceful::Maker

Defined in:
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

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Called automatically on ActionController::Base. Initializes various inheritable attributes.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 :shallow_parent
  base.class_attribute :model_namespace
  base.class_attribute :made_resourceful
  
  base.resourceful_callbacks = {}
  base.resourceful_responses = {}
  base.parents               = []
  base.model_namespace       = nil
  base.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.

Returns:

  • (Boolean)


76
77
78
# File 'lib/resourceful/maker.rb', line 76

def made_resourceful?
  self.class.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


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/resourceful/maker.rb', line 57

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