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

+ (Object) extended(base)

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



11
12
13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

- (Boolean) made_resourceful?

Returns whether or not make_resourceful has been called on this controller or any controllers it inherits from.

Returns:

  • (Boolean)


73
74
75
# File 'lib/resourceful/maker.rb', line 73

def made_resourceful?
  self.class.made_resourceful
end

- (Object) make_resourceful(options = {}, &block)

: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


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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