auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -1,77 +0,0 @@
1
- #!/bin/sh
2
-
3
- apt-get clean && apt-get update
4
-
5
- echo 'increasing the memory for apt'
6
- echo 'APT::Cache-Limit "516777216";' >> /etc/apt/apt.conf.d/70debconf
7
-
8
- echo 'running ubuntu_install.sh'
9
- rm -rf /usr/local/src/*
10
-
11
- echo 'updating apt'
12
- apt-get update
13
- # Get the essentials
14
- echo 'building essentials'
15
- apt-get -y install build-essential
16
-
17
- echo 'Installing git'
18
- apt-get -y install git-core rsync
19
-
20
- # Install ruby
21
- echo 'Installing ruby...'
22
- apt-get -y install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8
23
- ln -sf /usr/bin/ruby1.8 /usr/local/bin/ruby
24
- ln -sf /usr/bin/ri1.8 /usr/local/bin/ri
25
- ln -sf /usr/bin/rdoc1.8 /usr/local/bin/rdoc
26
- ln -sf /usr/bin/irb1.8 /usr/local/bin/irb
27
-
28
- # Install rubygems
29
- echo '-- Installing Rubygems'
30
- # if [[ ! -f /usr/local/src/rubygems-1.1.1 ]]; then
31
- cd /usr/local/src
32
- wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
33
- tar -xzf rubygems-1.1.1.tgz
34
- rm rubygems-1.1.1.tgz
35
- cd rubygems-1.1.1
36
- ruby setup.rb --no-rdoc --no-ri
37
- ln -sf /usr/bin/gem1.8 /usr/bin/gem
38
- # fi
39
-
40
- # Install gems
41
- # if [[ which pool | grep -v "bin" ]]; then
42
- gem update --system
43
- gem install SQS aws-s3 amazon-ec2 aska rake poolparty --no-rdoc --no-ri --no-test
44
- # fi
45
-
46
- # Install haproxy
47
- # if [[ which haproxy | grep -v "bin" ]]; then
48
- apt-get -y install haproxy
49
- echo 'Configuring haproxy logging'
50
- sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/haproxy
51
- sed -i 's/SYSLOGD=\"\"/SYSLOGD=\"-r\"/g' /etc/default/syslogd
52
- echo 'local0.* /var/log/haproxy.log' >> /etc/syslog.conf && /etc/init.d/sysklogd restart
53
- /etc/init.d/haproxy restart
54
- # fi
55
- # Install heartbeat
56
- # if [[ which heartbeat | grep -v "bin" ]]; then
57
- apt-get -y install heartbeat-2
58
- # fi
59
-
60
- # Install monit
61
- # if [[ which monit | grep -v "bin" ]]; then
62
- apt-get -y install monit
63
- sudo mkdir /etc/monit
64
- sed -i 's/startup=0/startup=1/g' /etc/default/monit
65
- /etc/init.d/monit start
66
- # fi
67
-
68
- # Install s3fuse
69
- # if [[ which s3fs | grep -v "bin" ]]; then
70
- apt-get install -y libcurl4-openssl-dev libxml2-dev libfuse-dev
71
- cd /usr/local/src && wget http://s3fs.googlecode.com/files/s3fs-r166-source.tar.gz
72
- tar -zxf s3fs-r166-source.tar.gz
73
- cd s3fs/ && make
74
- mv s3fs /usr/bin
75
- # fi
76
-
77
- echo ' - installed from script!'
data/config/monit.conf DELETED
@@ -1,9 +0,0 @@
1
- # Configuration for Monit, a monitoring tool
2
- set daemon 20 # Perform a check every 20 seconds
3
- set logfile /var/log/monit.log
4
-
5
- set httpd port 2812 and
6
- use address 0.0.0.0
7
- allow localhost
8
-
9
- include /etc/monit.d/*
@@ -1,8 +0,0 @@
1
- check process haproxy with pidfile /var/run/haproxy.pid
2
- start program = "/usr/sbin/haproxy -f /etc/haproxy.cfg -p /var/run/haproxy.pid"
3
- stop program = "/usr/bin/killall -9 haproxy"
4
- if totalmem is greater than 100.0 MB for 4 cycles then restart
5
- if cpu is greater than 50% for 2 cycles then alert
6
- if cpu is greater than 80% for 3 cycles then restart
7
- if loadavg(5min) greater than 10 for 8 cycles then restart
8
- group haproxy
File without changes
data/config/nginx.conf DELETED
@@ -1,24 +0,0 @@
1
- user usr usr;
2
- worker_processes 2;
3
-
4
- http {
5
- sendfile on;
6
- tcp_nopush on;
7
-
8
- keepalive_timeout 65;
9
- tcp_nodelay on;
10
-
11
- upstream fast_mongrels { server 127.0.0.1:4567; }
12
-
13
- server {
14
- listen 80;
15
- server_name srv;
16
- root /apps/poolparty;
17
-
18
- location / {
19
- proxy_pass http://fast_mongrels;
20
- break;
21
- }
22
-
23
- }
24
- }
@@ -1,37 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "Setting up pem files"
4
- :setup_pems
5
- # Move the hosts file
6
- echo "Moving the hosts file into place"
7
- :move_hostfile
8
- # Move the authkeys
9
- echo "Configuring the authkeys"
10
- :configure_authkeys
11
- # Move the config file
12
- echo "Moving custom config file for this cloud"
13
- :move_config_file
14
- # Reconfigure master if master?
15
- echo "If this is the master, I'm configuring it as the master now"
16
- :config_master
17
- # Configure haproxy
18
- echo "Configuring and starting haproxy"
19
- :configure_haproxy
20
- # Configure heartbeat
21
- echo "Moving all the resource.d files into place"
22
- :configure_resource_d
23
- # Start heartbeat
24
- echo "Configuring and starting heartbeat"
25
- :configure_heartbeat
26
- # Start s3fs
27
- echo "Mounting shared drive, if shared_bucket exists in config"
28
- :mount_s3_drive
29
- # Configure monit
30
- echo "Configuring monit"
31
- :configure_monit
32
- # Update the plugins
33
- echo "Updating plugins"
34
- :update_plugins
35
- # Run user tasks
36
- echo "Running user tasks"
37
- :user_tasks
@@ -1,23 +0,0 @@
1
- :app_name: "test_app"
2
- :user_id: "1619-6456-1164"
3
- :access_key: ""
4
- :secret_access_key: ""
5
- :ami: "ami-4f7a9f26"
6
- :size: small
7
- :polling_time: "30.seconds"
8
- :minimum_instances: 2
9
- :maximum_instances: 3
10
- :ec2_dir: "/Users/auser/.ec2"
11
- :keypair: testappkeypair
12
- :os: ubuntu
13
- :host_port: 80
14
- :client_port: 8001
15
- :shared_bucket: "poolparty-app-data"
16
- :services: nginx
17
- :environment: production
18
- :contract_when: |
19
- web > 10
20
- cpu < 0.2
21
- :expand_when: |
22
- cpu > 0.85
23
- web < 5
@@ -1,12 +0,0 @@
1
- #!/bin/sh
2
-
3
- :cloud_master_takeover
4
- :config_file
5
- :authkeys
6
- :ha_d
7
- :haresources
8
- :resources
9
- :monitrc
10
- :monit_d
11
- :haproxy
12
- :hosts
data/lib/core/array.rb DELETED
@@ -1,16 +0,0 @@
1
- =begin rdoc
2
- Array extensions
3
- =end
4
- require "enumerator"
5
- class Array
6
- # Collection with the index
7
- def collect_with_index &block
8
- self.enum_for(:each_with_index).collect &block
9
- end
10
- def runnable(quiet=true)
11
- self.join(" \n ").runnable(quiet)
12
- end
13
- def nice_runnable(quiet=true)
14
- self.join(" \n ").nice_runnable(quiet)
15
- end
16
- end
data/lib/core/hash.rb DELETED
@@ -1,11 +0,0 @@
1
- =begin rdoc
2
- Hash extentions
3
- =end
4
- class Hash
5
- def safe_merge(other_hash)
6
- merge(other_hash.delete_if {|k,v| has_key?(k) })
7
- end
8
- def safe_merge!(other_hash)
9
- merge!(other_hash.delete_if {|k,v| has_key?(k) && !v.nil? })
10
- end
11
- end
data/lib/core/kernel.rb DELETED
@@ -1,12 +0,0 @@
1
- =begin rdoc
2
- Kernel overloads
3
- =end
4
- module Kernel
5
- # Nice wait instead of sleep
6
- def wait(time=10)
7
- sleep time.is_a?(String) ? eval(time) : time
8
- end
9
- def as(klass_or_obj, &block)
10
- block.in_context(klass_or_obj).call
11
- end
12
- end
data/lib/core/object.rb DELETED
@@ -1,21 +0,0 @@
1
- =begin rdoc
2
- Basic, add an alias_method to the object class
3
- Add returning to the object
4
- =end
5
- class Object
6
- def my_methods
7
- self.methods.sort - (self.class.methods + self.class.superclass.methods)
8
- end
9
- def alias_method(new_id, original_id)
10
- original = self.method(original_id).to_proc
11
- define_method(new_id){|*args| original.call(*args)}
12
- end
13
- def returning(receiver)
14
- yield receiver
15
- receiver
16
- end
17
- def extended(&block)
18
- block.in_context(self).call
19
- self
20
- end
21
- end
data/lib/core/proc.rb DELETED
@@ -1,15 +0,0 @@
1
- class Proc
2
- def bind(object)
3
- block, time = self, Time.now
4
- (class << object; self; end).class_eval do
5
- method_name = "__bind_#{time.to_i}_#{time.usec}"
6
- define_method(method_name, &block)
7
- method = instance_method(method_name)
8
- remove_method(method_name)
9
- method
10
- end.bind(object)
11
- end
12
- def in_context(klass_or_obj)
13
- klass_or_obj.send(:eval, self.to_ruby)
14
- end
15
- end
@@ -1,58 +0,0 @@
1
- module PoolParty
2
- class PluginSpecHelper
3
- def self.define_stubs(klass, num=1)
4
- require File.dirname(__FILE__) + '/../../spec/helpers/ec2_mock'
5
-
6
- @klass = klass.send :new
7
- klass.stub!(:new).and_return @klass
8
-
9
- @master = Master.new
10
- @instances = define_instances(num)
11
-
12
- Master.stub!(:new).and_return @master
13
-
14
- @master.stub!(:execute_tasks).and_return true
15
- @master.stub!(:launch_minimum_instances).and_return true
16
- @master.stub!(:number_of_pending_instances).and_return 0
17
- @master.stub!(:get_node).with(0).and_return @instance0
18
-
19
- @master.stub!(:nodes).and_return @instances
20
-
21
- Kernel.stub!(:system).and_return "true"
22
-
23
- Provider.stub!(:install_poolparty).and_return true
24
-
25
- [@klass, @master, @instances]
26
- end
27
- def self.define_instances(num)
28
- # Too many gross evals
29
- returning [] do |arr|
30
- num.times do |i|
31
- eval <<-EOE
32
- @instance#{i} = RemoteInstance.new
33
- @instance#{i}.stub!(:ssh).and_return "true"
34
- @instance#{i}.stub!(:scp).and_return "true"
35
- @instance#{i}.stub!(:run).and_return "true"
36
- @instance#{i}.stub!(:name).and_return "node#{i}"
37
- @instance#{i}.stub!(:ip).and_return "127.0.0.#{i}"
38
- EOE
39
- arr << eval("@instance#{i}")
40
- end
41
- end
42
- end
43
- end
44
- end
45
-
46
- module Spec
47
- module Mocks
48
- module Methods
49
- def should_receive_at_least_once(sym, opts={}, &block)
50
- begin
51
- e = __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block).at_least(1)
52
- __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block).any_number_of_times
53
- e
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,133 +0,0 @@
1
- =begin rdoc
2
- Basic callbacks
3
- =end
4
- module PoolParty
5
- module Callbacks
6
- module ClassMethods
7
- def define_callback_module(mod)
8
- callbacks << mod
9
- end
10
- def define_callback_class(cla)
11
- classes << cla
12
- end
13
- def callback(type, m, *args, &block)
14
- arr = []
15
- args.each do |arg|
16
- arr << case arg.class.to_s
17
- when "Hash"
18
- arg.collect do |meth, klass|
19
- case klass.class.to_s
20
- when "String"
21
- define_callback_class(klass)
22
- "self.#{klass.to_s.downcase}.#{meth}(self)"
23
- else
24
- "#{klass}.send :#{meth}, self"
25
- end
26
- end
27
- when "Symbol"
28
- "self.send :#{arg}, self"
29
- end
30
- end
31
-
32
- string = ""
33
- if block_given?
34
- num = store_proc(block.to_proc)
35
- arr << <<-EOM
36
- self.class.get_proc(#{num}).bind(self).call
37
- EOM
38
- end
39
-
40
- string = create_eval_for_mod_with_string_and_type!(m, type) do
41
- arr.join("\n")
42
- end
43
-
44
- mMode = Module.new {eval string}
45
-
46
- define_callback_module(mMode)
47
- end
48
- def before(m, *args, &block)
49
- callback(:before, m, *args, &block)
50
- end
51
- def after(m, *args, &block)
52
- callback(:after, m, *args, &block)
53
- end
54
-
55
- def create_eval_for_mod_with_string_and_type!(meth, type=nil, &block)
56
- str = ""
57
- case type
58
- when :before
59
- str << <<-EOD
60
- def #{meth}(*args)
61
- #{yield}
62
- super
63
- end
64
- EOD
65
- when :after
66
- str << <<-EOD
67
- def #{meth}(*args)
68
- super
69
- #{yield}
70
- end
71
- EOD
72
- else
73
- str << <<-EOD
74
- def #{meth}(*args)
75
- #{yield}
76
- end
77
- EOD
78
- end
79
- str
80
- end
81
-
82
- def callbacks
83
- @callbacks ||= []
84
- end
85
- def classes
86
- @classes ||= []
87
- end
88
- end
89
-
90
- module InstanceMethods
91
- def initialize(*args)
92
- extend_callbacks
93
- extend_callback_methods
94
- end
95
-
96
- def extend_callback_methods
97
- unless self.class.classes.empty?
98
- self.class.classes.each do |klass|
99
- m = %{def #{klass.to_s.downcase};@#{klass.to_s.downcase} ||= #{klass}.new;end}
100
- self.class.class_eval m unless self.class.method_defined?(m)
101
- end
102
- end
103
- end
104
-
105
- def extend_callbacks
106
- unless self.class.callbacks.empty?
107
- self.class.callbacks.each do |mod|
108
- self.extend(mod)
109
- end
110
- end
111
- end
112
- end
113
-
114
- module ProcStoreMethods
115
- def store_proc(proc)
116
- proc_storage << proc
117
- proc_storage.index(proc)
118
- end
119
- def get_proc(num)
120
- proc_storage[num]
121
- end
122
- def proc_storage
123
- @proc_store ||= []
124
- end
125
- end
126
-
127
- def self.included(receiver)
128
- receiver.extend ClassMethods
129
- receiver.extend ProcStoreMethods
130
- receiver.send :include, InstanceMethods
131
- end
132
- end
133
- end