Sha256: c8ad660836915bcbf3da0ffd3d6c8918d45ee13bc8bf3f3b4ac16535a688fb2f

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

module Ramaze
  module Helper
    module REST
      def self.included(klass)
        klass.class_eval do
          trait :REST => {
            'GET' => [], 'PUT' => [],
            'POST' => [], 'DELETE' => [],
            :any => [],
          }
          extend Indicate

          def self.method_added(name)
            name = name.to_s
            active = trait[:REST][:active] ||= :any
            trait[:REST][active] << name
          end
        end
      end

      module Indicate
        def on(http_method)
          hm = http_method.to_s.upcase
          trait[:REST][hm] = []
          trait[:REST][:active] = hm
        end

        (%w[GET PUT POST DELETE] << :any).each do |http_method|
          define_method("on_#{http_method.downcase}") do |*args|
            if args.empty?
              on(http_method)
            else
              trait[:REST][http_method] += args.flatten
            end
          end
        end
      end
    end
  end
end

# POST /foo/bar
# methods_on_post[/foo/bar]

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
clivecrous-ramaze-0.3.9.5 lib/ramaze/helper/rest.rb
ramaze-2008.06 lib/ramaze/helper/rest.rb