Skip to content

Phobos98/grape_has_scope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grape_has_scope

This is a Plataformatec's gem has_scope implementation to use with Grape API

Installation

Add the grape and grape_has_scope gems to Gemfile.

gem 'grape'
gem 'grape_has_scope'

And then execute:

bundle

Usage

The usage is similar to the original implementation, so you can read the detailed instructions on the original has_scope page

The only difference is that you should define used scopes in the before block of your Grape::API, like this

class Posts < Grape::API

  before do
    has_scope :by_author
    has_scope :page
    has_scope :per_page
  end

  resource :posts do

    desc 'Returns the list of posts'
    params do
      optional :by_author, type: Integer, desc: "Filter by: Author ID"
      optional :page, type: Integer, default: 1, desc: "Page number (default: 1)"
      optional :per_page, type: Integer, default: 30, desc: "Number of elements per page (default: 30)"
    end
    get '' do
      apply_scopes(Post)
    end
  end
end

Tests

The tests were just copied from the original gem, so they will not work, and I did not yet have time to update them :) So feel free to implement them and contribute, if you wish

About

has_scope implementation for use with Grape

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages