Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yhirano55/banken-dsl
:dog2::electric_plug: Directory define query methods to the controller for a Banken loyalty class by DSL
https://github.com/yhirano55/banken-dsl
authorization banken dsl rails
Last synced: 3 days ago
JSON representation
:dog2::electric_plug: Directory define query methods to the controller for a Banken loyalty class by DSL
- Host: GitHub
- URL: https://github.com/yhirano55/banken-dsl
- Owner: yhirano55
- License: mit
- Created: 2017-07-10T02:40:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T05:39:34.000Z (over 7 years ago)
- Last Synced: 2025-01-03T04:39:52.227Z (4 days ago)
- Topics: authorization, banken, dsl, rails
- Language: Ruby
- Homepage: https://github.com/yhirano55/banken-dsl
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Banken::DSL
[![Build Status](https://travis-ci.org/yhirano55/banken-dsl.svg?branch=master)](https://travis-ci.org/yhirano55/banken-dsl)
[![Gem Version](https://badge.fury.io/rb/banken-dsl.svg)](https://badge.fury.io/rb/banken-dsl)This plugin gives directly define query methods to the controller for a Banken loyalty class by DSL
## Installation
``` ruby
gem "banken-dsl"
```Include Banken in your application controller:
``` ruby
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include Banken
protect_from_forgery
end
```Optionally, you can run the generator, which will set up an application loyalty
with some useful defaults for you:``` sh
rails g banken:install
```After generating your application loyalty, restart the Rails server so that Rails
can pick up any classes in the new `app/loyalties/` directory.## Usage
This plugin provides DSL to define query methods to the Controller without creating a loyalty class:
``` ruby
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
authorization_policy do
index { true }
show { true }
create { user.admin? }
update { user.admin? && record.unpublished? }
destroy { user.admin? && record.unpublished? }
endbefore_action :set_post, only: [:show, :edit, :update, :destroy]
def index
@posts = Post.all
enddef show
end
end
```You can define the loyalty class by `authorization_policy` method as same as this code:
```ruby
# app/loyalties/posts_loyalty.rb
class PostsLoyalty < ApplicationLoyalty
def index?
true
enddef show?
true
enddef create?
user.admin?
enddef update?
user.admin? && record.unpublished?
enddef destroy?
user.admin? && record.unpublished?
end
end
```## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).