simple_allow 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c8c2b2b792d200cab8bc510145dd6080dfb722c
4
+ data.tar.gz: 61e011a01c7a924640d54e43a66f02f308ecf2c3
5
+ SHA512:
6
+ metadata.gz: 69543474970df9e92f6e9762015eeb7bf597098d2a6cf1da764435ada54923be589e5c8bb3d8af93172ee0478d584d66467c64e7b2284891933fa33b37a66a9e
7
+ data.tar.gz: d1eace9e049adcda014a5f911be810895a0141e3d8843de7f985bd54e1b2b63ee68b08b64724f83e9bc4c84066382f8e74765fef6531c23e123e31a184eddbe8
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Daniel Alves
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # simple_allow
2
+
3
+ ```
4
+ gem 'simple_allow'
5
+ ```
6
+
7
+ ```ruby
8
+ string = 'one'
9
+ symbol = :one
10
+
11
+ string.allow('one', 'two') #=> "one"
12
+ string.allow('two') #=> nil
13
+
14
+ symbol.allow(:one, :two) #=> :one
15
+ symbol.allow(:two) #=> nil
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SimpleAllow'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ begin
20
+ require 'rspec/core/rake_task'
21
+ RSpec::Core::RakeTask.new(:spec)
22
+ task :default => :spec
23
+ rescue LoadError
24
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAllow
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'simple_allow/version'
2
+
3
+ module SimpleAllow
4
+ def allow(*allowed)
5
+ allowed.include?(self) ? self : nil
6
+ end
7
+ end
8
+
9
+ String.send(:include, SimpleAllow)
10
+ Symbol.send(:include, SimpleAllow)
@@ -0,0 +1,30 @@
1
+ require_relative '../lib/simple_allow'
2
+
3
+ RSpec.describe SimpleAllow do
4
+ let(:string) { 'one' }
5
+ let(:symbol) { :one }
6
+
7
+ describe 'with string' do
8
+ it 'filters not allowed strings' do
9
+ result = string.allow('two', 'three')
10
+ expect(result).to be_nil
11
+ end
12
+
13
+ it 'returns allowed strings' do
14
+ result = string.allow('one')
15
+ expect(result).to eq string
16
+ end
17
+ end
18
+
19
+ describe 'with symbol' do
20
+ it 'filters not allowed symbols' do
21
+ result = symbol.allow(:two, :three)
22
+ expect(result).to be_nil
23
+ end
24
+
25
+ it 'returns allowed symbols' do
26
+ result = symbol.allow(:one, :two)
27
+ expect(result).to eq symbol
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_allow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Alves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: Simple allow method for strings and symbols
28
+ email:
29
+ - daniel@danielalves.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/simple_allow.rb
38
+ - lib/simple_allow/version.rb
39
+ - spec/simple_allow_spec.rb
40
+ homepage: https://github.com/alvesdan/simple_allow
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Simple allow method for strings and symbols
64
+ test_files:
65
+ - spec/simple_allow_spec.rb