Sha256: c2a72891a2529be7061053bcf82cc84b492ddf95ebce14091215c503c4264e95

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

module MakeRestful::ClassMethods

  def authorize_resource!
    before_filter do
      @resource = @resource.authorize(auth_token)
      @resource.params = params if resource.respond_to?(:params=)
      @instance = @resource.find(params[:id]) if params[:id] && @resource.respond_to?(:find)
    end
  end

  private

  def resource(klass)
    before_filter do
      resource.params = params.except(:action, :controller, :id) if resource.respond_to?(:params=)
      klass = klass.to_s.camelize.constantize
      @resource ||= klass
      @instance = resource.find(params[:id]) if params[:id] && @resource.respond_to?(:find)
    end
  end

  def allow_methods(*methods)
    self.send :define_method, :allowed_methods do
      methods.flatten
    end
  end

  def allow_formats(*formats)
    self.send :define_method, :allowed_formats do
      formats.flatten
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
make_restful-0.0.1.pre1 lib/make_restful/class_methods.rb