monkey-patches 0.0.0 → 0.5.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/LICENSE +16 -17
- data/README.rdoc +14 -12
- data/Rakefile +33 -44
- data/VERSION +1 -1
- data/lib/monkey/patch/array/from.rb +13 -0
- data/lib/monkey/patch/array/to.rb +11 -0
- data/lib/monkey/patch/object/blank.rb +13 -0
- data/lib/monkey/patch/object/metaclass.rb +10 -0
- data/lib/monkey/patch/object/returning.rb +49 -0
- data/lib/monkey/patch/object/try.rb +31 -0
- data/lib/monkey/patches.rb +5 -0
- metadata +54 -23
- data/.document +0 -5
- data/.gitignore +0 -21
- data/lib/monkey-patches.rb +0 -0
- data/test/helper.rb +0 -10
- data/test/test_monkey-patches.rb +0 -7
data/LICENSE
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2010 Stephen Karl Touset
|
2
2
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
the following conditions:
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
10
9
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
13
12
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
OF
|
20
|
-
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
= monkey-patches
|
2
2
|
|
3
|
-
|
3
|
+
This is a set of commonly-used extensions to Ruby core classes, implemented
|
4
|
+
using the Monkey[http://github.com/stouset/monkey] monkeypatching framework.
|
4
5
|
|
5
|
-
==
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(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)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
6
|
+
== Usage
|
14
7
|
|
15
|
-
|
8
|
+
The easiest way to use monkey-patches is to simply require the whole set of
|
9
|
+
patches.
|
16
10
|
|
17
|
-
|
11
|
+
require 'monkey/patches'
|
12
|
+
|
13
|
+
Monkey.patch(Array, :blank?) { [].blank? }
|
14
|
+
|
15
|
+
Alternatively, you can require patches as-needed.
|
16
|
+
|
17
|
+
require 'monkey/patch/object/metaclass'
|
18
|
+
|
19
|
+
Monkey.patch(String, :metaclass) { "foo".metaclass }
|
data/Rakefile
CHANGED
@@ -1,53 +1,42 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
gem.summary = %Q{A set of monkeypatches for the monkey gem}
|
9
|
-
gem.description = %Q{This is just a dummy package to reserve the name until the project is ready to be released}
|
10
|
-
gem.email = "stephen@touset.org"
|
11
|
-
gem.homepage = "http://github.com/stouset/monkey-patches"
|
12
|
-
gem.authors = ["Stephen Touset"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/version_task'
|
6
|
+
require 'spec/rake/spectask'
|
20
7
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
8
|
+
spec = Gem::Specification.new do |s|
|
9
|
+
s.name = 'monkey-patches'
|
10
|
+
s.version = Version.current
|
11
|
+
s.summary = 'Monkeypatches build on the monkey extension framework'
|
12
|
+
s.homepage = 'http://github.com/stouset/monkey-patches'
|
13
|
+
|
14
|
+
s.author = 'Stephen Touset'
|
15
|
+
s.email = 'stephen@touset.org'
|
16
|
+
|
17
|
+
s.files = Dir['[A-Z]*', 'lib/**/*.rb']
|
18
|
+
|
19
|
+
s.extra_rdoc_files = Dir['*.rdoc']
|
20
|
+
s.rdoc_options = %w{ --main README.rdoc }
|
21
|
+
|
22
|
+
s.add_dependency 'monkey'
|
23
|
+
|
24
|
+
s.add_development_dependency 'version'
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
27
|
+
Rake::GemPackageTask.new(spec) do |gem|
|
28
|
+
gem.need_tar = true
|
39
29
|
end
|
40
30
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
Rake::RDocTask.new do |doc|
|
32
|
+
doc.title = "monkey-patches #{Version.current}"
|
33
|
+
doc.rdoc_dir = 'doc'
|
34
|
+
doc.main = 'README.rdoc'
|
35
|
+
doc.rdoc_files.include('*.rdoc')
|
36
|
+
doc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
Rake::VersionTask.new do |v|
|
40
|
+
v.with_git_tag = true
|
41
|
+
v.with_gemspec = spec
|
53
42
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'monkey'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2005-2010 David Heinemeier Hansson
|
5
|
+
#
|
6
|
+
Monkey.see(Object) do
|
7
|
+
#
|
8
|
+
# Returns +value+ after yielding +value+ to the block. This simplifies the
|
9
|
+
# process of constructing an object, performing work on the object, and then
|
10
|
+
# returning the object from a method. It is a Ruby-ized realization of the K
|
11
|
+
# combinator, courtesy of Mikael Brockman.
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
#
|
15
|
+
# # Without returning
|
16
|
+
# def foo
|
17
|
+
# values = []
|
18
|
+
# values << "bar"
|
19
|
+
# values << "baz"
|
20
|
+
# return values
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# foo # => ['bar', 'baz']
|
24
|
+
#
|
25
|
+
# # returning with a local variable
|
26
|
+
# def foo
|
27
|
+
# returning values = [] do
|
28
|
+
# values << 'bar'
|
29
|
+
# values << 'baz'
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# foo # => ['bar', 'baz']
|
34
|
+
#
|
35
|
+
# # returning with a block argument
|
36
|
+
# def foo
|
37
|
+
# returning [] do |values|
|
38
|
+
# values << 'bar'
|
39
|
+
# values << 'baz'
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# foo # => ['bar', 'baz']
|
44
|
+
#
|
45
|
+
def returning(value)
|
46
|
+
yield(value)
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'monkey'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2005-2010 David Heinemeier Hansson
|
5
|
+
#
|
6
|
+
Monkey.see(Object) do
|
7
|
+
#
|
8
|
+
# Invokes the method identified by the symbol +method+, passing it any arguments
|
9
|
+
# and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
|
10
|
+
#
|
11
|
+
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
|
12
|
+
# and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
|
13
|
+
#
|
14
|
+
# ==== Examples
|
15
|
+
#
|
16
|
+
# Without try
|
17
|
+
# @person && @person.name
|
18
|
+
# or
|
19
|
+
# @person ? @person.name : nil
|
20
|
+
#
|
21
|
+
# With try
|
22
|
+
# @person.try(:name)
|
23
|
+
#
|
24
|
+
# +try+ also accepts arguments and/or a block, for the method it is trying
|
25
|
+
# Person.try(:find, 1)
|
26
|
+
# @people.try(:collect) {|p| p.name}
|
27
|
+
#
|
28
|
+
def try(method, *args, &block)
|
29
|
+
self.nil? ? nil : self.send(method, *args, &block)
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkey-patches
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Stephen Touset
|
@@ -9,66 +15,91 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-07-14 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
name: monkey
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: version
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
20
40
|
requirements:
|
21
41
|
- - ">="
|
22
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
23
46
|
version: "0"
|
24
|
-
|
25
|
-
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description:
|
26
50
|
email: stephen@touset.org
|
27
51
|
executables: []
|
28
52
|
|
29
53
|
extensions: []
|
30
54
|
|
31
55
|
extra_rdoc_files:
|
32
|
-
- LICENSE
|
33
56
|
- README.rdoc
|
34
57
|
files:
|
35
|
-
- .document
|
36
|
-
- .gitignore
|
37
58
|
- LICENSE
|
38
|
-
- README.rdoc
|
39
59
|
- Rakefile
|
60
|
+
- README.rdoc
|
40
61
|
- VERSION
|
41
|
-
- lib/monkey
|
42
|
-
-
|
43
|
-
-
|
62
|
+
- lib/monkey/patch/array/from.rb
|
63
|
+
- lib/monkey/patch/array/to.rb
|
64
|
+
- lib/monkey/patch/object/blank.rb
|
65
|
+
- lib/monkey/patch/object/metaclass.rb
|
66
|
+
- lib/monkey/patch/object/returning.rb
|
67
|
+
- lib/monkey/patch/object/try.rb
|
68
|
+
- lib/monkey/patches.rb
|
44
69
|
has_rdoc: true
|
45
70
|
homepage: http://github.com/stouset/monkey-patches
|
46
71
|
licenses: []
|
47
72
|
|
48
73
|
post_install_message:
|
49
74
|
rdoc_options:
|
50
|
-
- --
|
75
|
+
- --main
|
76
|
+
- README.rdoc
|
51
77
|
require_paths:
|
52
78
|
- lib
|
53
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
54
81
|
requirements:
|
55
82
|
- - ">="
|
56
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
57
87
|
version: "0"
|
58
|
-
version:
|
59
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
60
90
|
requirements:
|
61
91
|
- - ">="
|
62
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
63
96
|
version: "0"
|
64
|
-
version:
|
65
97
|
requirements: []
|
66
98
|
|
67
99
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.3.
|
100
|
+
rubygems_version: 1.3.7
|
69
101
|
signing_key:
|
70
102
|
specification_version: 3
|
71
|
-
summary:
|
72
|
-
test_files:
|
73
|
-
|
74
|
-
- test/test_monkey-patches.rb
|
103
|
+
summary: Monkeypatches build on the monkey extension framework
|
104
|
+
test_files: []
|
105
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/lib/monkey-patches.rb
DELETED
File without changes
|
data/test/helper.rb
DELETED
data/test/test_monkey-patches.rb
DELETED