Skip to content

Commit

Permalink
bump to 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonborg committed Aug 3, 2017
1 parent b48ede2 commit 7a9ad54
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 196 deletions.
98 changes: 4 additions & 94 deletions README.md
@@ -1,101 +1,11 @@
# Forbidium
[![Gem Version](https://badge.fury.io/rb/forbidium.svg)](https://badge.fury.io/rb/forbidium)
[![Code Climate](https://codeclimate.com/github/msimonborg/forbidium/badges/gpa.svg)](https://codeclimate.com/github/msimonborg/forbidium)
[![Build Status](https://travis-ci.org/msimonborg/forbidium.svg?branch=master)](https://travis-ci.org/msimonborg/forbidium)
[![Coverage Status](https://coveralls.io/repos/github/msimonborg/forbidium/badge.svg?branch=master)](https://coveralls.io/github/msimonborg/forbidium?branch=master)
# I was Forbidium
# Now I'm [Allowable](https://github.com/msimonborg/allowable)

Filter hashes by setting allowed or forbidden values for specific keys.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'forbidium'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install forbidium

## Usage
The gem will add four methods to `Hash`: `#allow`, `#allow!`, `#forbid`, and `#forbid!`

```ruby
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 # => {}
```

#### Type sensitive for `Hash`

```ruby
hash = { 'one' => 'one', 'two' => 'two' }

hash.forbid(one: 'one') # => { "one" => "one", "two" => "two" }

hash.forbid('one' => 'one') # => { "two" => "two" }
```

## With Rails and strong parameters

When added to the `Gemfile` in a Rails project, `ActionController::Parameters` will automatically receive these methods so you can use them with your `strong_parameters`:

```ruby
def user_params
params.require(:user).permit(:email, :password, :role).forbid(role: ['sys_admin', 'owner'])
end
```

#### Type insensitive for `HashWithIndifferentAccess`
```ruby
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 Forbidium` to mix in the methods.

## Platform support

This gem should work with Ruby >= 2.0.0, however at the moment it is only tested for Ruby >= 2.2.2

Tested against:
* MRI 2.2.2
* MRI 2.3.0
* MRI 2.3.4
* MRI 2.4.1
* JRuby 9.1.6.0
* JRuby HEAD
* MRI HEAD

## Development

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](https://rubygems.org).
I'll still work. All I do is install the latest version of `allowable` and `include Allowable`. You might as well do that directly.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/msimonborg/forbidium.
Bug reports and pull requests are welcome on GitHub at https://github.com/msimonborg/allowable.


## License
Expand Down
8 changes: 6 additions & 2 deletions forbidium.gemspec
Expand Up @@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
spec.authors = ['M. Simon Borg']
spec.email = ['msimonborg@gmail.com']

spec.summary = 'Filter hash keys based on allowed and forbidden values.'
spec.description = 'Filter hash keys based on allowed and forbidden values.'
spec.summary = 'Filter hash keys based on allowed and forbidden values. Renamed "Allowable".'
spec.description = 'Filter hash keys based on allowed and forbidden values. Renamed "Allowable".'
spec.homepage = 'https://github.com/msimonborg/forbidium'
spec.license = 'MIT'

Expand All @@ -22,8 +22,12 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'allowable'

spec.required_ruby_version = '>= 2.0.0'

spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'rake', '~> 10.0'

spec.post_install_message = "`Forbidium` has been renamed to `Allowable`. Please remove `forbidium` from your Gemfile and replace it with `allowable`. `forbidium` just installs the latest version of `allowable` anyway, so it will still work. But you won't be able to lock the version. Do the right thing and switch to `allowable`"
end
27 changes: 24 additions & 3 deletions lib/forbidium.rb
@@ -1,6 +1,27 @@
# frozen_string_literal: true

require 'allowable'
require 'forbidium/version'
require 'forbidium/forbidium'
require 'forbidium/core_ext/hash'
require 'forbidium/railtie' if defined? Rails

# frozen_string_literal: true

# Filter hashes by setting allowed or forbidden values for specific keys.
#
# 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 # => {}
module Forbidium
include Allowable
end
17 changes: 0 additions & 17 deletions lib/forbidium/allow.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/forbidium/core_ext/hash.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/forbidium/forbid.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/forbidium/forbidium.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/forbidium/railtie.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/forbidium/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Forbidium
VERSION = '1.2.0'
VERSION = '2.0.0'
end
4 changes: 2 additions & 2 deletions spec/forbidium/allow_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Forbidium::Allow do
describe Forbidium do
let(:symbol_hash) { { hi: 'hi', hello: 'hello' } }
let(:string_hash) { { 'hi' => 'hi', 'hello' => 'hello' } }

Expand All @@ -11,7 +11,7 @@ class AllowTestObject; end
expect(AllowTestObject.new).not_to respond_to :allow
expect(AllowTestObject.new).not_to respond_to :allow!

AllowTestObject.class_eval { include Forbidium::Allow }
AllowTestObject.class_eval { include Forbidium }

expect(AllowTestObject.new).to respond_to :allow
expect(AllowTestObject.new).to respond_to :allow!
Expand Down
4 changes: 2 additions & 2 deletions spec/forbidium/forbid_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Forbidium::Forbid do
describe Forbidium do
let(:symbol_hash) { { hi: 'hi', hello: 'hello' } }
let(:string_hash) { { 'hi' => 'hi', 'hello' => 'hello' } }

Expand All @@ -11,7 +11,7 @@ class ForbidTestObject; end
expect(ForbidTestObject.new).not_to respond_to :forbid
expect(ForbidTestObject.new).not_to respond_to :forbid!

ForbidTestObject.class_eval { include Forbidium::Forbid }
ForbidTestObject.class_eval { include Forbidium }

expect(ForbidTestObject.new).to respond_to :forbid
expect(ForbidTestObject.new).to respond_to :forbid!
Expand Down
18 changes: 8 additions & 10 deletions spec/forbidium_spec.rb
@@ -1,19 +1,17 @@
# frozen_string_literal: true

describe Forbidium do
it 'includes Forbidium::Allow and Forbidium::Forbid when included' do
class ForbidiumTestObject; end
describe Allowable do
it 'includes Allowable::Allow and Allowable::Forbid when included' do
class AllowableTestObject; end

expect(ForbidiumTestObject.include?(Forbidium::Allow)).not_to be true
expect(ForbidiumTestObject.include?(Forbidium::Forbid)).not_to be true
expect(AllowableTestObject.include?(Allowable)).not_to be true

ForbidiumTestObject.class_eval { include Forbidium }
AllowableTestObject.class_eval { include Forbidium }

expect(ForbidiumTestObject.include?(Forbidium::Allow)).to be true
expect(ForbidiumTestObject.include?(Forbidium::Forbid)).to be true
expect(AllowableTestObject.include?(Allowable)).to be true
end

it 'is included in Hash when required' do
expect(Hash.include?(Forbidium)).to be true
it 'Allowable is included in Hash when required' do
expect(Hash.include?(Allowable)).to be true
end
end
4 changes: 2 additions & 2 deletions spec/rails/action_controller/parameters_spec.rb
Expand Up @@ -3,8 +3,8 @@
ActiveSupport.run_load_hooks(:action_controller, ActionController::Base)

describe ActionController::Parameters do
it 'includes Forbidium' do
expect(ActionController::Parameters.include?(Forbidium)).to be true
it 'includes Allowable' do
expect(ActionController::Parameters.include?(Allowable)).to be true
end

let(:params) do
Expand Down

0 comments on commit 7a9ad54

Please sign in to comment.