monkey_patch 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.4"
7
+ gem "rcov", ">= 0"
8
+
9
+ # not strictly a development dependency, but needed in order to test the ability
10
+ # to detect a specific version of a gem
11
+ gem "fake_gem", "0.1.1"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ fake_gem (0.1.1)
6
+ git (1.2.5)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rake (0.9.2)
12
+ rcov (0.9.10)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ fake_gem (= 0.1.1)
28
+ jeweler (~> 1.6.4)
29
+ rcov
30
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 David Cuddeback
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = monkey_patch
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to monkey_patch
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 David Cuddeback. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "monkey_patch"
18
+ gem.homepage = "http://github.com/dcuddeback/monkey_patch"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Manage monkey patches for installed gems}
21
+ gem.description = %Q{Manage monkey patches for installed gems}
22
+ gem.email = "david@identified.com"
23
+ gem.authors = ["David Cuddeback"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "monkey_patch #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,7 @@
1
+ module MonkeyPatch
2
+ class Railtie < Rails::Railtie
3
+ initializer "monkey_patch.initialization" do |app|
4
+ MonkeyPatch.logger = Rails.logger
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+
3
+ module MonkeyPatch
4
+ class Error < RuntimeError
5
+ end
6
+
7
+ class MissingGem < Error
8
+ attr_reader :gem_name, :version
9
+
10
+ def initialize(gem_name, version)
11
+ @gem_name = gem_name
12
+ @version = version
13
+ end
14
+
15
+ def to_s
16
+ "attempted to patch missing gem: #{gem_name} v#{version}"
17
+ end
18
+ end
19
+
20
+ class UpdateRequired < Error
21
+ attr_reader :gem, :version
22
+
23
+ def initialize(gem, version)
24
+ @gem = gem
25
+ @version = version
26
+ end
27
+
28
+ def to_s
29
+ "attempted to patch wrong version of gem: #{gem.name} v#{version} (installed version is #{gem.version.to_s})"
30
+ end
31
+ end
32
+
33
+ class Patcher
34
+ attr_reader :gem, :version
35
+
36
+ def initialize(gem, version)
37
+ @gem = gem
38
+ @version = version
39
+ end
40
+
41
+ def announce(patch)
42
+ MonkeyPatch.logger && MonkeyPatch.logger.info("MonkeyPatch (#{gem} v#{version}): #{patch}")
43
+ end
44
+ end
45
+
46
+ class << self
47
+ attr_accessor :logger
48
+
49
+ def for(gem_name, version, &block)
50
+ gem = find_gem(gem_name)
51
+
52
+ raise MissingGem.new(gem_name, version) if gem.nil?
53
+ raise UpdateRequired.new(gem, version) if gem.version.to_s != version
54
+
55
+ block.call(MonkeyPatch::Patcher.new(gem_name, version))
56
+ end
57
+
58
+ private
59
+
60
+ def find_gem(name)
61
+ if Gem::Specification.respond_to?(:find_all_by_name)
62
+ Gem::Specification.find_all_by_name(name.to_s).first
63
+ else
64
+ Gem.searcher.find(name)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ if defined?(Rails) && Rails::VERSION::MAJOR >= 3
71
+ require 'monkey_patch/railtie'
72
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "monkey_patch"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Cuddeback"]
12
+ s.date = "2011-10-03"
13
+ s.description = "Manage monkey patches for installed gems"
14
+ s.email = "david@identified.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/monkey_patch.rb",
29
+ "lib/monkey_patch/railtie.rb",
30
+ "monkey_patch.gemspec",
31
+ "spec/monkey_patch_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/dcuddeback/monkey_patch"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "Manage monkey patches for installed gems"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ s.add_development_dependency(%q<fake_gem>, ["= 0.1.1"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_dependency(%q<rcov>, [">= 0"])
54
+ s.add_dependency(%q<fake_gem>, ["= 0.1.1"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<fake_gem>, ["= 0.1.1"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'logger'
3
+
4
+ describe MonkeyPatch do
5
+ describe "#for" do
6
+ let(:good_patch) do
7
+ lambda {
8
+ MonkeyPatch.for(:fake_gem, '0.1.1') do |mp|
9
+ mp.announce("testing MonkeyPatch#for")
10
+ end
11
+ }
12
+ end
13
+
14
+ let(:patch_for_wrong_version) do
15
+ lambda {
16
+ MonkeyPatch.for(:rspec, "0") do |mp|
17
+ mp.announce("testing MonkeyPatch#for")
18
+ end
19
+ }
20
+ end
21
+
22
+ let(:patch_for_missing_gem) do
23
+ lambda {
24
+ MonkeyPatch.for(:this_is_not_a_gem, "1.0") do |mp|
25
+ mp.announce("testing MonkeyPatch#for")
26
+ end
27
+ }
28
+ end
29
+
30
+ let(:logger) { Logger.new(nil) }
31
+
32
+ context "on correct gem version" do
33
+ subject { good_patch }
34
+
35
+ context "with logger set" do
36
+ before { MonkeyPatch.logger = logger }
37
+
38
+ it { should_not raise_error }
39
+ it "should announce patch in log file" do
40
+ logger.should_receive(:info).with("MonkeyPatch (fake_gem v0.1.1): testing MonkeyPatch#for")
41
+ subject.call
42
+ end
43
+ end
44
+
45
+ context "without logger set" do
46
+ it { should_not raise_error }
47
+ it "should not announce the patch" do
48
+ logger.should_not_receive(:info)
49
+ subject.call
50
+ end
51
+ end
52
+ end
53
+
54
+ context "with incorrect gem version" do
55
+ subject { patch_for_wrong_version }
56
+ it { should raise_error(MonkeyPatch::UpdateRequired) }
57
+ end
58
+
59
+ context "with missing gem" do
60
+ subject { patch_for_missing_gem }
61
+ it { should raise_error(MonkeyPatch::MissingGem) }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'monkey_patch'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monkey_patch
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - David Cuddeback
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 0
31
+ version: 2.3.0
32
+ version_requirements: *id001
33
+ name: rspec
34
+ prerelease: false
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ version_requirements: *id002
49
+ name: bundler
50
+ prerelease: false
51
+ type: :development
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 1
61
+ - 6
62
+ - 4
63
+ version: 1.6.4
64
+ version_requirements: *id003
65
+ name: jeweler
66
+ prerelease: false
67
+ type: :development
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ version_requirements: *id004
79
+ name: rcov
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - "="
87
+ - !ruby/object:Gem::Version
88
+ hash: 25
89
+ segments:
90
+ - 0
91
+ - 1
92
+ - 1
93
+ version: 0.1.1
94
+ version_requirements: *id005
95
+ name: fake_gem
96
+ prerelease: false
97
+ type: :development
98
+ description: Manage monkey patches for installed gems
99
+ email: david@identified.com
100
+ executables: []
101
+
102
+ extensions: []
103
+
104
+ extra_rdoc_files:
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ files:
108
+ - .document
109
+ - .rspec
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.rdoc
114
+ - Rakefile
115
+ - VERSION
116
+ - lib/monkey_patch.rb
117
+ - lib/monkey_patch/railtie.rb
118
+ - monkey_patch.gemspec
119
+ - spec/monkey_patch_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: http://github.com/dcuddeback/monkey_patch
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.10
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Manage monkey patches for installed gems
154
+ test_files: []
155
+