File: dsl.rb

package info (click to toggle)
ruby-inherited-resources 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 824 kB
  • sloc: ruby: 4,388; makefile: 6
file content (26 lines) | stat: -rw-r--r-- 693 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module InheritedResources
  # Allows controllers to write actions using a class method DSL.
  #
  #   class MyController < InheritedResources::Base
  #     create! do |success, failure|
  #       success.html { render :text => "It works!" }
  #     end
  #   end
  #
  module DSL
    def self.included(base)
      ACTIONS.each do |action|
        base.class_eval <<-WRITTER
          def self.#{action}!(options={}, &block)
            define_method :__#{action}, &block
            class_eval <<-ACTION
              def #{action}
                super(\#{options.inspect}, &method(:__#{action}))
              end
            ACTION
          end
        WRITTER
      end
    end
  end
end