Skip to content

rspine/restrictions

Repository files navigation

Spine::Restrictions

Gem Version Dependency Status Test Coverage Code Climate security Inline docs Codeship Status for rspine/restrictions

Restrictions registration for application context.

Installation

To install it, add the gem to your Gemfile:

gem 'spine-restrictions'

Then run bundle. If you're not using Bundler, just gem install spine-restrictions.

Usage

# Restriction can be module or class, which defines `restricted?` method based
# on context.
class UserSuspensionRestriction
  def restricted?(context)
    !!context.subject.suspended_at
  end
end

restrictions = Spine::Restrictions::Collection.new
restrictions.register(UserSuspensionRestriction)
  .restrict(:write, :all)
  .restrict(:update, :all)
  .restrict(:delete, :all)
  .except(:all, :billing)

restrictions.restricted?(context, :write, :tasks)
# => <UserSuspensionRestriction:0x007f8e51ad7960>

About

Restrictions registration for application context.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages