Restrictions registration for application context.
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
.
# 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>