monkey_do 0.1.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.
Files changed (6) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +5 -0
  3. data/README.txt +66 -0
  4. data/Rakefile +11 -0
  5. data/lib/monkey_do.rb +79 -0
  6. metadata +83 -0
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 0.1.0 / 2011-10-20
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,5 @@
1
+ Manifest.txt
2
+ README.txt
3
+ Rakefile
4
+ History.txt
5
+ lib/monkey_do.rb
data/README.txt ADDED
@@ -0,0 +1,66 @@
1
+ = monkey_do
2
+
3
+ * http://rubygems.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Utility for applying patches to installed gems.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * In order to have a stable environment if one has applied patches to a vendor's
12
+ gems a rake task is provided and available when one includes MonkeyPatch.
13
+
14
+ == SYNOPSIS:
15
+
16
+ Rakefile:
17
+ require 'rubygems'
18
+ require 'monkey_do'
19
+ include MonkeyDoPatch
20
+ MonkeyDoPatch.conf('/full/path/to/your_conf.yaml')
21
+
22
+
23
+ Here's an examle monkey config file:
24
+ - :patch:
25
+ :source: monkey_patches/telnet.rb
26
+ :destination: /opt/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-telnet-0.0.1/lib/net/ssh/
27
+ - :patch:
28
+ :source: /some/other/patch/file
29
+ :destination: /copied/to/some/other/directory
30
+
31
+
32
+ Once the module MonkeyPatch is included you will have a task called build:patch.
33
+
34
+
35
+ == REQUIREMENTS:
36
+
37
+ * platform_helpers
38
+
39
+ == INSTALL:
40
+
41
+ * gem install monkey_patch
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2011 Cliff Cyphers
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'monkey_do' do
7
+ developer('Cliff Cyphers', 'cliff.cyphers@gmail.com')
8
+ extra_deps << ['platform_helpers', '0.1.2']
9
+ end
10
+
11
+ # vim: syntax=ruby
data/lib/monkey_do.rb ADDED
@@ -0,0 +1,79 @@
1
+ base = File.expand_path(File.dirname(__FILE__))
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ require 'fileutils'
5
+ require 'find'
6
+
7
+
8
+ module MonkeyDoPatch
9
+ def self.conf(file)
10
+ MonkeyDo.module_eval {
11
+ raise ArgumentError unless File.exists?(file)
12
+ @conf = file
13
+ }
14
+ end
15
+ VERSION = '0.1.0'
16
+ def self.included(obj)
17
+ obj.class_eval {
18
+ Proc.new {
19
+ namespace :build do
20
+ desc "apply patches and update template files"
21
+ task :patch do
22
+ MonkeyDo.monkey_patch
23
+ end
24
+ end
25
+ }.call
26
+ }
27
+ end
28
+ end
29
+
30
+ module MonkeyDo
31
+ @conf = nil
32
+ def self.monkey_patch
33
+ patch_cfg = YAML::load_file(@conf)
34
+
35
+ patch_cfg.each { |monkey_item|
36
+ if monkey_item.has_key?(:patch)
37
+ if Kernel.const_defined?('DEBUG')
38
+ puts "copying #{monkey_item[:patch][:source]} to #{monkey_item[:patch][:destination]}" if DEBUG
39
+ end
40
+
41
+ FileUtils.cp monkey_item[:patch][:source], monkey_item[:patch][:destination]
42
+ elsif monkey_item.has_key?(:update_text)
43
+ unless File.exists?(monkey_item[:update_text][:file])
44
+ raise "no file found for #{monkey_item[:update_text][:file]}"
45
+ end
46
+ if monkey_item[:update_text].has_key?(:search_eval)
47
+ search = eval(monkey_item[:update_text][:search_eval])
48
+ elsif monkey_item[:update_text].has_key?(:search)
49
+ search = monkey_item[:update_text][:search]
50
+ end
51
+ if monkey_item[:update_text].has_key?(:replace_eval)
52
+ replace = eval(monkey_item[:update_text][:replace_eval])
53
+ if monkey_item[:update_text].has_key?(:string_wrap)
54
+ replace = "\"#{replace}\""
55
+ end
56
+
57
+ elsif monkey_item[:update_text].has_key?(:replace)
58
+ replace = monkey_item[:update_text][:replace]
59
+ end
60
+
61
+ file = monkey_item[:update_text][:file]
62
+ backup_file = "#{file}.#{Time.now.usec}"
63
+ updated_file = File.readlines(file).to_s.gsub("#{search}", "#{replace}")
64
+ begin
65
+ FileUtils.mv(file, backup_file)
66
+ fd=File.open(file, 'w+')
67
+ fd.puts updated_file
68
+ FileUtils.rm_f backup_file
69
+ rescue => e
70
+ puts e.inspect
71
+ FileUtils.mv(backup_file, file)
72
+ end
73
+ end
74
+
75
+ }
76
+ end
77
+
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monkey_do
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Cliff Cyphers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: platform_helpers
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: hoe
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "2.12"
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: Utility for applying patches to installed gems.
38
+ email:
39
+ - cliff.cyphers@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - Manifest.txt
46
+ - README.txt
47
+ - History.txt
48
+ files:
49
+ - Manifest.txt
50
+ - README.txt
51
+ - Rakefile
52
+ - History.txt
53
+ - lib/monkey_do.rb
54
+ homepage: http://rubygems.org
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --main
60
+ - README.txt
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project: monkey_do
78
+ rubygems_version: 1.8.11
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Utility for applying patches to installed gems.
82
+ test_files: []
83
+