subelsky_enhancements 1.0.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.
- data/MIT-LICENSE +20 -0
- data/README.textile +5 -0
- data/Rakefile +15 -0
- data/TODO.txt +3 -0
- data/VERSION +1 -0
- data/lib/subelsky_enhancements.rb +5 -0
- data/lib/subelsky_enhancements/hash.rb +31 -0
- data/subelsky_enhancements.gemspec +48 -0
- data/test/hash_test.rb +34 -0
- metadata +63 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mike Subelsky
|
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.textile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "subelsky_enhancements"
|
5
|
+
gemspec.summary = gemspec.description = "Various Ruby patches and enhancements I carry from project to project"
|
6
|
+
gemspec.email = "mike@subelsky.com"
|
7
|
+
gemspec.homepage = "http://github.com/subelsky/enhancements"
|
8
|
+
gemspec.authors = ["Mike Subelsky"]
|
9
|
+
gemspec.test_files = %w(test/hash_test.rb)
|
10
|
+
end
|
11
|
+
|
12
|
+
Jeweler::GemcutterTasks.new
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
15
|
+
end
|
data/TODO.txt
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Slightly modified from
|
2
|
+
# * https://wincent.com/wiki/Fixtures_considered_harmful%3F
|
3
|
+
# By way of Topfunky's Peepcode Rspec screencasts
|
4
|
+
|
5
|
+
module HashEnhancement
|
6
|
+
|
7
|
+
# Filter keys out of a Hash.
|
8
|
+
#
|
9
|
+
# { :a => 1, :b => 2, :c => 3 }.except(:a)
|
10
|
+
# => { :b => 2, :c => 3 }
|
11
|
+
|
12
|
+
def except(*keys)
|
13
|
+
self.reject { |k,v| keys.flatten.include?(k || k.to_sym) }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a Hash with only the pairs identified by +keys+.
|
17
|
+
#
|
18
|
+
# { :a => 1, :b => 2, :c => 3 }.only(:a)
|
19
|
+
# => { :a => 1 }
|
20
|
+
|
21
|
+
def only(*keys)
|
22
|
+
self.reject { |k,v| !keys.include?(k || k.to_sym) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
unless Hash.instance_methods.include?(:except) || Hash.instance_methods.include?(:only)
|
28
|
+
Hash.class_eval do
|
29
|
+
include HashEnhancement
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{subelsky_enhancements}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mike Subelsky"]
|
12
|
+
s.date = %q{2010-01-02}
|
13
|
+
s.description = %q{Various Ruby patches and enhancements I carry from project to project}
|
14
|
+
s.email = %q{mike@subelsky.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.textile",
|
21
|
+
"Rakefile",
|
22
|
+
"TODO.txt",
|
23
|
+
"VERSION",
|
24
|
+
"lib/subelsky_enhancements.rb",
|
25
|
+
"lib/subelsky_enhancements/hash.rb",
|
26
|
+
"subelsky_enhancements.gemspec",
|
27
|
+
"test/hash_test.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/subelsky/enhancements}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Various Ruby patches and enhancements I carry from project to project}
|
34
|
+
s.test_files = [
|
35
|
+
"test/hash_test.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
else
|
44
|
+
end
|
45
|
+
else
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/test/hash_test.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__),'..','lib','subelsky_enhancements','hash')
|
3
|
+
|
4
|
+
class TestHash < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def hash
|
7
|
+
@hash ||= { :a => 1, :b => 2, :c => 3, :d => 4 }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_except_with_one_key
|
11
|
+
assert_equal({ :a => 1, :b => 2, :d => 4 }, hash.except(:c))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_except_with_multiple_keys
|
15
|
+
assert_equal({ :b => 2, :c => 3 }, hash.except(:a,:d))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_except_with_absent_key
|
19
|
+
assert_equal(hash, hash.except(:e))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_only_with_one_key
|
23
|
+
assert_equal({ :a => 1 }, hash.only(:a))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_only_with_multiple_keys
|
27
|
+
assert_equal({ :b => 2, :c => 3, :d => 4 }, hash.only(:b,:c,:d))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_only_with_absent_key
|
31
|
+
assert_equal({}, hash.only(:e))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: subelsky_enhancements
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Subelsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-02 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Various Ruby patches and enhancements I carry from project to project
|
17
|
+
email: mike@subelsky.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.textile
|
27
|
+
- Rakefile
|
28
|
+
- TODO.txt
|
29
|
+
- VERSION
|
30
|
+
- lib/subelsky_enhancements.rb
|
31
|
+
- lib/subelsky_enhancements/hash.rb
|
32
|
+
- subelsky_enhancements.gemspec
|
33
|
+
- test/hash_test.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/subelsky/enhancements
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Various Ruby patches and enhancements I carry from project to project
|
62
|
+
test_files:
|
63
|
+
- test/hash_test.rb
|