
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Filter hashes by setting allowed or forbidden values for specific keys.
Add this line to your application's Gemfile:
gem 'allowable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install allowable
The gem will add four methods to Hash
: #allow
, #allow!
, #forbid
, and #forbid!
hash = { one: 'one', two: 'two' }
hash.forbid(one: 'one') # => { two: 'two' }
hash.allow(one: 'two') # => { two: 'two' }
hash.allow(one: ['one', 'two']) # => { one: 'one', two: 'two' }
hash.forbid(one: ['one', 'two']) # => { two: 'two' }
hash.allow!(one: 'two') # => { two: 'two' }
hash.forbid!(two: 'two') # => {}
hash # => {}
hash.merge(one: ['one', 1]).forbid(one: 'one') # => { one: ["one", 1] }
hash.merge(one: ['one', 1]).forbid(one: ['one', 1]) # => {}
Hash
hash = { 'one' => 'one', 'two' => 'two' }
hash.forbid(one: 'one') # => { "one" => "one", "two" => "two" }
hash.forbid('one' => 'one') # => { "two" => "two" }
If ActiveSupport::HashWithIndifferentAccess
is defined it will receive the methods. This automatically makes them available in ActionController::Parameters
for Rails 4 and 3. Rails 3 requires that you add gem 'strong_parameters'
to your Gemfile
in order to use strong parameters.
Starting in Rails 5, ActionController::Parameters
no longer inherits from ActiveSupport::HashWithIndifferentAccess
. When allowable
is added to the Gemfile
in a Rails 5+ project, load hooks will add the methods directly to ActionController::Parameters
so you can use them with your strong parameters.
def user_params
params.require(:user).permit(:email, :password, :role).forbid(role: ['sys_admin', 'owner'])
end
HashWithIndifferentAccess
and ActionController::Parameters
params = ActionController::Parameters.new('one' => 'one', 'two' => 'two').permit(:one, :two)
params.forbid(one: 'one').to_h # => { "two" => "two" }
params.forbid('one' => 'one').to_h # => { "two" => "two" }
If your custom Hash
-like class implements #delete
and the #[]
finder, you can include Allowable
to mix in the methods.
class MyHash
include Allowable
end
The core module should work with all rubies. It is tested for MRI Ruby >= 1.9.3 and JRuby 9.1.6.0
Rails compatibility is currently being tested only for versions ~> 3.2, ~> 4.2, and ~> 5.1.
Tested against:
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/msimonborg/allowable.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that allowable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.