forbidium 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1043ce4d9d849b044c480c05b412003f0b00deb6
4
- data.tar.gz: 9ccce27c23c6d6853dfc5cdca0059ff08bdfe89d
3
+ metadata.gz: 7357a934edea8da3fad3521e262b325f5a074aa2
4
+ data.tar.gz: 3314c60c18cfe8712cc6554dd30d3ab439320264
5
5
  SHA512:
6
- metadata.gz: fa045780d0b51b068941114a4599035c7fedf5cac0e50fe092aad3fb890c32fa651c6b5030759c829de0cf2889e0fcf2df53370d4113f3fa6cbce3b11734aab7
7
- data.tar.gz: 34c0875b4c8a3b6cc19dc14319ab31422af161517328ad21eeaf04d702936569e5fef0740a63ef749e9513da0d23baf0b0b66f06cc8020afe2e144bf3f081d7e
6
+ metadata.gz: 36b5426bae95cac10e625fc75fcf5e6c6d84c383808f7fefeb638e255bb6126448db590c85a1a4300181da78ae3b7343db912dbc6704784b612601955fc6e977
7
+ data.tar.gz: 31bdeb20fa5b6759fd6d007ccab67d96fd4f587dc131fc4f5e043391710d1a48fcab00edbb48754d9bf60c2e7c6700fec74d9381c9ac8da68f6c2086acd00706
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Forbidium
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/forbidium`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Filter hashes by setting allowed or forbidden values for specific keys.
6
4
 
7
5
  ## Installation
8
6
 
@@ -21,9 +19,23 @@ Or install it yourself as:
21
19
  $ gem install forbidium
22
20
 
23
21
  ## Usage
22
+ ```ruby
23
+ hash = { one: 'one', two: 'two' }
24
+
25
+ hash.forbid(one: 'one') # => { two: 'two' }
26
+
27
+ hash.allow(one: 'two') # => { two: 'two' }
28
+
29
+ hash.allow(one: ['one', 'two']) # => { one: 'one', two: 'two' }
24
30
 
25
- TODO: Write usage instructions here
31
+ hash.forbid(one: ['one', 'two']) # => { two: 'two' }
26
32
 
33
+ hash.allow!(one: 'two') # => { two: 'two' }
34
+
35
+ hash.forbid!(two: 'two') # => {}
36
+
37
+ hash # => {}
38
+ ```
27
39
  ## Development
28
40
 
29
41
  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.
@@ -32,10 +44,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
44
 
33
45
  ## Contributing
34
46
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/forbidium.
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/msimonborg/forbidium.
36
48
 
37
49
 
38
50
  ## License
39
51
 
40
52
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -1,4 +1,5 @@
1
1
  module Forbidium
2
+ # Adds the #allow and #allow! methods
2
3
  module Allow
3
4
  def allow(filters = {})
4
5
  dup.allow!(filters)
@@ -1,3 +1,4 @@
1
+ # Add #allow, #allow!, #forbid, and #forbid! to Hash
1
2
  class Hash
2
3
  include Forbidium
3
4
  end
@@ -1,4 +1,5 @@
1
1
  module Forbidium
2
+ # Adds the #forbid and #forbid! methods
2
3
  module Forbid
3
4
  def forbid(filters = {})
4
5
  dup.forbid!(filters)
@@ -3,6 +3,23 @@
3
3
  require 'forbidium/allow'
4
4
  require 'forbidium/forbid'
5
5
 
6
+ # Filter hashes by setting allowed or forbidden values for specific keys.
7
+ #
8
+ # hash = { one: 'one', two: 'two' }
9
+ #
10
+ # hash.forbid(one: 'one') # => { two: 'two' }
11
+ #
12
+ # hash.allow(one: 'two') # => { two: 'two' }
13
+ #
14
+ # hash.allow(one: ['one', 'two']) # => { one: 'one', two: 'two' }
15
+ #
16
+ # hash.forbid(one: ['one', 'two']) # => { two: 'two' }
17
+ #
18
+ # hash.allow!(one: 'two') # => { two: 'two' }
19
+ #
20
+ # hash.forbid!(two: 'two') # => {}
21
+ #
22
+ # hash # => {}
6
23
  module Forbidium
7
24
  def self.included(base)
8
25
  [Forbidium::Allow, Forbidium::Forbid].each { |mod| base.include mod }
@@ -1,6 +1,7 @@
1
1
  require 'rails/railtie'
2
2
 
3
3
  module Forbidium
4
+ # Railtie initializer that adds Forbidium methods to controller params
4
5
  class Railtie < ::Rails::Railtie
5
6
  initializer :forbidium do
6
7
  ActiveSupport.on_load :action_controller do
@@ -1,3 +1,3 @@
1
1
  module Forbidium
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/forbidium.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'forbidium/version'
2
-
3
2
  require 'forbidium/forbidium'
4
3
  require 'forbidium/core_ext/hash'
5
-
6
4
  require 'forbidium/railtie' if defined? Rails
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forbidium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg