зеркало из https://github.com/github/tainted_hash.git
add a readme
This commit is contained in:
Родитель
75c1360704
Коммит
3d5a59d55e
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2012 Rick Olson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,43 @@
|
|||
# Tainted Hash
|
||||
|
||||
A TaintedHash is a wrapper around a normal Hash that only exposes the keys that
|
||||
have been approved. This is useful in cases where a Hash is built from user
|
||||
input. By forcing the developer to approve keys, no unexpected keys are passed
|
||||
to data stores. Because of this specific use case, it is assumed all keys are
|
||||
strings.
|
||||
|
||||
By default, no keys have been approved.
|
||||
|
||||
```ruby
|
||||
hash = {'a' => 1, 'b' => 2', 'c' => 3}
|
||||
tainted = TaintedHash.new hash
|
||||
```
|
||||
|
||||
You can access keys manually to get the value and approve them:
|
||||
|
||||
```ruby
|
||||
tainted.include?(:a) # false
|
||||
tainted['a'] # Returns 2
|
||||
tainted[:a] # Symbols are OK too.
|
||||
tainted.include?(:a) # true
|
||||
tainted.keys # ['a']
|
||||
|
||||
tainted.fetch(:b) # Returns 2
|
||||
tainted.include?(:b) # true
|
||||
tainted.keys # ['a', 'b']
|
||||
|
||||
tainted.values_at(:b, :c) # Returns [2, 3]
|
||||
tainted.include?(:c) # true
|
||||
tainted.keys # ['a', 'b', 'c']
|
||||
```
|
||||
|
||||
## Note on Patches/Pull Requests
|
||||
1. Fork the project on GitHub.
|
||||
2. Make your feature addition or bug fix.
|
||||
3. Add tests for it. This is important so I don't break it in a future version
|
||||
unintentionally.
|
||||
4. Commit, do not mess with rakefile, version, or history. (if you want to have
|
||||
your own version, that is fine but bump version in a commit by itself I can
|
||||
ignore when I pull)
|
||||
5. Send me a pull request. Bonus points for topic branches.
|
||||
|
|
@ -11,22 +11,22 @@ Gem::Specification.new do |s|
|
|||
## Leave these as is they will be modified for you by the rake gemspec task.
|
||||
## If your rubyforge_project name is different, then edit it and comment out
|
||||
## the sub! line in the Rakefile
|
||||
s.name = 'faraday'
|
||||
s.name = 'tainted_hash'
|
||||
s.version = '0.7.5'
|
||||
s.date = '2011-10-04'
|
||||
s.rubyforge_project = 'faraday'
|
||||
|
||||
## Make sure your summary is short. The description may be as long
|
||||
## as you like.
|
||||
s.summary = "HTTP/REST API client library."
|
||||
s.description = "HTTP/REST API client library."
|
||||
s.summary = "Hash wrapper."
|
||||
s.description = "Hash wrapper."
|
||||
|
||||
## List the primary authors. If there are a bunch of authors, it's probably
|
||||
## better to set the email to an email list or something. If you don't have
|
||||
## a custom homepage, consider using your GitHub URL or the like.
|
||||
s.authors = ["Rick Olson"]
|
||||
s.email = 'technoweenie@gmail.com'
|
||||
s.homepage = 'https://github.com/github/tainted_love'
|
||||
s.homepage = 'https://github.com/technoweenie/tainted_hash'
|
||||
|
||||
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
||||
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
||||
|
|
Загрузка…
Ссылка в новой задаче