monkey-patches 0.0.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,20 +1,19 @@
1
- Copyright (c) 2009 Stephen Touset
1
+ Copyright (c) 2010 Stephen Karl Touset
2
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:
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
- included in all copies or substantial portions of the Software.
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
- 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.
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.
@@ -1,17 +1,19 @@
1
1
  = monkey-patches
2
2
 
3
- Description goes here.
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
- == Note on Patches/Pull Requests
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
- == Copyright
8
+ The easiest way to use monkey-patches is to simply require the whole set of
9
+ patches.
16
10
 
17
- Copyright (c) 2010 Stephen Touset. See LICENSE for details.
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
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "monkey-patches"
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
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
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
- begin
29
- require 'rcov/rcovtask'
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
- task :test => :check_dependencies
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
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
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "monkey-patches #{version}"
51
- rdoc.rdoc_files.include('README*')
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.0.0
1
+ 0.5.0
@@ -0,0 +1,13 @@
1
+ require 'monkey'
2
+
3
+ #
4
+ # Copyright (c) 2005-2010 David Heinemeier Hansson
5
+ #
6
+ Monkey.see(Array) do
7
+ #
8
+ # Returns the tail of the array from +position+.
9
+ #
10
+ def from(position)
11
+ self[position .. -1]
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Copyright (c) 2005-2010 David Heinemeier Hansson
3
+ #
4
+ Monkey.see(Array) do
5
+ #
6
+ # Returns the beginning of the array up to +position+.
7
+ #
8
+ def to(position)
9
+ self[0 .. position]
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'monkey'
2
+
3
+ #
4
+ # Copyright (c) 2005-2010 David Heinemeier Hansson
5
+ #
6
+ Monkey.see(Object) do
7
+ #
8
+ # An object is blank if it's false, empty, or a whitespace string.
9
+ #
10
+ def blank?
11
+ respond_to?(:empty?) ? empty? : !self
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ require 'monkey'
2
+
3
+ Monkey.see(Object) do
4
+ #
5
+ # Returns the object's singleton class.
6
+ #
7
+ def metaclass
8
+ class << self; self; end
9
+ end
10
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ require 'pathname'
2
+
3
+ Dir[Pathname.new(__FILE__).dirname.join('patch/**/*.rb')].each do |patch|
4
+ require patch
5
+ 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
- version: 0.0.0
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-02-26 00:00:00 -05:00
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: thoughtbot-shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
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
- version:
25
- description: This is just a dummy package to reserve the name until the project is ready to be released
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-patches.rb
42
- - test/helper.rb
43
- - test/test_monkey-patches.rb
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
- - --charset=UTF-8
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.5
100
+ rubygems_version: 1.3.7
69
101
  signing_key:
70
102
  specification_version: 3
71
- summary: A set of monkeypatches for the monkey gem
72
- test_files:
73
- - test/helper.rb
74
- - test/test_monkey-patches.rb
103
+ summary: Monkeypatches build on the monkey extension framework
104
+ test_files: []
105
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
File without changes
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'monkey-patches'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMonkeyPatches < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end