subelsky_power_tools 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/.gitignore +1 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +39 -0
- data/Guardfile +9 -0
- data/MIT-LICENSE +20 -0
- data/README.md +25 -0
- data/Rakefile +10 -0
- data/lib/subelsky_power_tools/ext/exception.rb +19 -0
- data/lib/subelsky_power_tools/ext/hash.rb +54 -0
- data/lib/subelsky_power_tools/version.rb +3 -0
- data/lib/subelsky_power_tools.rb +2 -0
- data/spec/exception_spec.rb +12 -0
- data/spec/hash_spec.rb +30 -0
- data/spec/spec_helper.rb +31 -0
- data/subelsky_power_tools.gemspec +23 -0
- metadata +83 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2-p180-patched@subelsky_power_tools --create
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
subelsky_power_tools (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
growl (1.0.3)
|
11
|
+
guard (0.4.2)
|
12
|
+
thor (~> 0.14.6)
|
13
|
+
guard-rspec (0.4.0)
|
14
|
+
guard (>= 0.4.0)
|
15
|
+
guard-spork (0.2.0)
|
16
|
+
guard (>= 0.2.2)
|
17
|
+
spork (>= 0.8.4)
|
18
|
+
rb-fsevent (0.4.0)
|
19
|
+
rspec (2.6.0)
|
20
|
+
rspec-core (~> 2.6.0)
|
21
|
+
rspec-expectations (~> 2.6.0)
|
22
|
+
rspec-mocks (~> 2.6.0)
|
23
|
+
rspec-core (2.6.4)
|
24
|
+
rspec-expectations (2.6.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.6.0)
|
27
|
+
spork (0.8.5)
|
28
|
+
thor (0.14.6)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
growl (= 1.0.3)
|
35
|
+
guard-rspec (= 0.4.0)
|
36
|
+
guard-spork (= 0.2.0)
|
37
|
+
rb-fsevent (= 0.4.0)
|
38
|
+
rspec
|
39
|
+
subelsky_power_tools!
|
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 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.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Subelsky Power Tools Gem
|
2
|
+
|
3
|
+
This is a collection of Ruby extensions and utilities I've been carting around from project to project.
|
4
|
+
Many are taken from the [Facets](http://rubyworks.github.com/facets/) project (I just don't want to
|
5
|
+
include that whole gem in my codebases).
|
6
|
+
|
7
|
+
The name is a tribute to [Topfunky Power Tools](http://topfunky.net/svn/plugins/topfunky_power_tools/).
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
gem install subelsky_power_tools
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
The gem does not automatically require anything, so you can pick and choose which extensions get
|
16
|
+
added, by requiring them individually, e.g.:
|
17
|
+
|
18
|
+
require 'subelsky_power_tools/ext/hash'
|
19
|
+
require 'subelsky_power_tools/ext/exception'
|
20
|
+
|
21
|
+
See the individual extensions in `lib` or their tests in the `spec` directory.
|
22
|
+
|
23
|
+
# Problems? Questions?
|
24
|
+
|
25
|
+
Email <mike@subelsky.com> or file an issue on [GitHub](https://github.com/subelsky/subelsky_power_tools). Thanks!
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# https://github.com/rubyworks/facets/blob/master/lib/core/facets/exception/detail.rb
|
2
|
+
class Exception
|
3
|
+
|
4
|
+
# Pretty string output of exception/error
|
5
|
+
# object useful for helpful debug messages.
|
6
|
+
#
|
7
|
+
# Input:
|
8
|
+
# The Exception/StandardError object
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# The pretty printed string
|
12
|
+
#
|
13
|
+
# CREDIT: George Moschovitis
|
14
|
+
|
15
|
+
def detail
|
16
|
+
return %{#{self.class.name}: #{message}\n#{backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# https://github.com/rubyworks/facets/blob/master/lib/core/facets/hash/except.rb
|
2
|
+
# https://github.com/rubyworks/facets/blob/master/lib/core/facets/hash/slice.rb
|
3
|
+
|
4
|
+
class Hash
|
5
|
+
|
6
|
+
# Returns a new hash less the given keys.
|
7
|
+
def except(*less_keys)
|
8
|
+
hash = dup
|
9
|
+
less_keys.each{ |k| hash.delete(k) }
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
|
13
|
+
# Replaces hash with new hash less the given keys.
|
14
|
+
# This returns the hash of keys removed.
|
15
|
+
#
|
16
|
+
# h = {:a=>1, :b=>2, :c=>3}
|
17
|
+
# h.except!(:a) #=> {:a=>1}
|
18
|
+
# h #=> {:b=>2,:c=>3}
|
19
|
+
#
|
20
|
+
# Returns a Hash of the removed pairs.
|
21
|
+
def except!(*rejected)
|
22
|
+
removed = {}
|
23
|
+
rejected.each{ |k| removed[k] = delete(k) }
|
24
|
+
removed
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a new hash with only the given keys.
|
28
|
+
#
|
29
|
+
# h = {:a=>1, :b=>2}
|
30
|
+
# h.only(:a) #=> {:a=>1}
|
31
|
+
#
|
32
|
+
def only(*keep_keys)
|
33
|
+
hash = {}
|
34
|
+
keep_keys.each do |key|
|
35
|
+
hash[key] = fetch(key)
|
36
|
+
end
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
|
40
|
+
# Replaces hash with a new hash having only the given keys.
|
41
|
+
# This return the hash of keys removed.
|
42
|
+
#
|
43
|
+
# h = {:a=>1, :b=>2}
|
44
|
+
# h.only!(:a) #=> {:b=>2}
|
45
|
+
# h #=> {:a=>1}
|
46
|
+
#
|
47
|
+
# Returns a Hash of the removed pairs.
|
48
|
+
def only!(*keep_keys)
|
49
|
+
rejected = keys - keep_keys
|
50
|
+
removed = {}
|
51
|
+
rejected.each{ |k| removed[k] = delete(k) }
|
52
|
+
removed
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "subelsky_power_tools/ext/exception"
|
3
|
+
|
4
|
+
describe Exception do
|
5
|
+
it "reports details" do
|
6
|
+
begin
|
7
|
+
raise StandardError.new("something bad happened")
|
8
|
+
rescue StandardError => e
|
9
|
+
e.detail.should =~ /StandardError: something bad happened\n/
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "subelsky_power_tools/ext/hash"
|
3
|
+
|
4
|
+
describe Hash do
|
5
|
+
|
6
|
+
let(:h) do
|
7
|
+
{ :a => 1, :b => 2, :c => 3 }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should except given keys" do
|
11
|
+
h.except(:a).should == { :b => 2, :c => 3 }
|
12
|
+
h.except(:a,:c).should == { :b => 2 }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should perform destructive exceptions" do
|
16
|
+
h.except!(:c).should == { :c => 3 }
|
17
|
+
h.should == { :a => 1, :b => 2 }
|
18
|
+
h.except!(:a,:b)
|
19
|
+
h.should be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should include given keys only" do
|
23
|
+
h.only(:a,:b).should == { :a => 1, :b => 2 }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should perform destructive inclusion" do
|
27
|
+
h.only!(:c).should == { :a => 1, :b => 2}
|
28
|
+
h.should == { :c => 3 }
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spork"
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__),"..","lib"))
|
3
|
+
|
4
|
+
Spork.prefork do
|
5
|
+
require "rspec"
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.mock_with :rspec
|
9
|
+
|
10
|
+
last_gc_run = Time.now
|
11
|
+
|
12
|
+
config.before(:each) do
|
13
|
+
GC.disable
|
14
|
+
end
|
15
|
+
|
16
|
+
config.after(:each) do
|
17
|
+
if Time.now - last_gc_run > 1.0
|
18
|
+
GC.enable
|
19
|
+
GC.start
|
20
|
+
last_gc_run = Time.now
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rspec/expectations'
|
27
|
+
require 'rspec/core/expecting/with_rspec'
|
28
|
+
end
|
29
|
+
|
30
|
+
Spork.each_run do
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'lib/subelsky_power_tools/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{subelsky_power_tools}
|
6
|
+
s.version = SubelskyPowerTools::VERSION
|
7
|
+
s.authors = ["Mike Subelsky"]
|
8
|
+
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
9
|
+
s.email = %q{mike@subelsky.com}
|
10
|
+
s.extra_rdoc_files = %w(README.md)
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.homepage = %q{http://github.com/subelsky/subelsky_power_tools}
|
13
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.summary = %q{This is a collection of Ruby extensions and utilities I've been carting around from project to project.}
|
16
|
+
s.description = <<-DESC
|
17
|
+
This is a collection of Ruby extensions and utilities I've been carting around from project to project.
|
18
|
+
Many are taken from the Facets project (I just don't want to include that whole gem in my codebases).
|
19
|
+
DESC
|
20
|
+
s.test_files = `git ls-files spec`.split("\n")
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
s.license = "MIT"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: subelsky_power_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Subelsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-05 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &2157564940 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2157564940
|
26
|
+
description: ! "This is a collection of Ruby extensions and utilities I've been carting
|
27
|
+
around from project to project. \nMany are taken from the Facets project (I just
|
28
|
+
don't want to include that whole gem in my codebases).\n"
|
29
|
+
email: mike@subelsky.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .rspec
|
37
|
+
- .rvmrc
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- Guardfile
|
41
|
+
- MIT-LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/subelsky_power_tools.rb
|
45
|
+
- lib/subelsky_power_tools/ext/exception.rb
|
46
|
+
- lib/subelsky_power_tools/ext/hash.rb
|
47
|
+
- lib/subelsky_power_tools/version.rb
|
48
|
+
- spec/exception_spec.rb
|
49
|
+
- spec/hash_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- subelsky_power_tools.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/subelsky/subelsky_power_tools
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.6.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: This is a collection of Ruby extensions and utilities I've been carting around
|
79
|
+
from project to project.
|
80
|
+
test_files:
|
81
|
+
- spec/exception_spec.rb
|
82
|
+
- spec/hash_spec.rb
|
83
|
+
- spec/spec_helper.rb
|