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,37 +0,0 @@
1
- <?xml version="1.0"?>
2
- <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01/">
3
- <reservationSet>
4
- <item>
5
- <reservationId>r-6d539104</reservationId>
6
- <ownerId>161964561164</ownerId>
7
- <groupSet>
8
- <item>
9
- <groupId>default</groupId>
10
- </item>
11
- </groupSet>
12
- <instancesSet>
13
- <item>
14
- <instanceId>i-60bc6a09</instanceId>
15
- <imageId>ami-4bb05422</imageId>
16
- <instanceState>
17
- <code>16</code>
18
- <name>running</name>
19
- </instanceState>
20
- <privateDnsName>domU-12-31-39-00-86-15.compute-1.internal</privateDnsName>
21
- <dnsName>ec2-75-101-242-244.compute-1.amazonaws.com</dnsName>
22
- <reason/>
23
- <keyName>auser</keyName>
24
- <amiLaunchIndex>0</amiLaunchIndex>
25
- <productCodes/>
26
- <instanceType>m1.small</instanceType>
27
- <launchTime>2008-06-25T20:14:35.000Z</launchTime>
28
- <placement>
29
- <availabilityZone>us-east-1b</availabilityZone>
30
- </placement>
31
- <kernelId>aki-a71cf9ce</kernelId>
32
- <ramdiskId>ari-a51cf9cc</ramdiskId>
33
- </item>
34
- </instancesSet>
35
- </item>
36
- </reservationSet>
37
- </DescribeInstancesResponse>
@@ -1,69 +0,0 @@
1
- <?xml version="1.0"?>
2
- <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01/">
3
- <reservationSet>
4
- <item>
5
- <reservationId>r-7678ba1f</reservationId>
6
- <ownerId>802044448869</ownerId>
7
- <groupSet>
8
- <item>
9
- <groupId>default</groupId>
10
- </item>
11
- </groupSet>
12
- <instancesSet>
13
- <item>
14
- <instanceId>i-6df12704</instanceId>
15
- <imageId>ami-3057b259</imageId>
16
- <instanceState>
17
- <code>16</code>
18
- <name>running</name>
19
- </instanceState>
20
- <privateDnsName>ip-10-251-199-97.ec2.internal</privateDnsName>
21
- <dnsName>ec2-72-44-39-61.compute-1.amazonaws.com</dnsName>
22
- <reason/>
23
- <keyName>pjc-keypair</keyName>
24
- <amiLaunchIndex>0</amiLaunchIndex>
25
- <productCodes/>
26
- <instanceType>m1.small</instanceType>
27
- <launchTime>2008-06-26T21:55:52.000Z</launchTime>
28
- <placement>
29
- <availabilityZone>us-east-1c</availabilityZone>
30
- </placement>
31
- <kernelId>aki-a71cf9ce</kernelId>
32
- <ramdiskId>ari-a51cf9cc</ramdiskId>
33
- </item>
34
- </instancesSet>
35
- </item>
36
- <item>
37
- <reservationId>r-4978ba20</reservationId>
38
- <ownerId>802044448869</ownerId>
39
- <groupSet>
40
- <item>
41
- <groupId>default</groupId>
42
- </item>
43
- </groupSet>
44
- <instancesSet>
45
- <item>
46
- <instanceId>i-6cf12705</instanceId>
47
- <imageId>ami-3057b259</imageId>
48
- <instanceState>
49
- <code>16</code>
50
- <name>running</name>
51
- </instanceState>
52
- <privateDnsName>ip-10-251-198-230.ec2.internal</privateDnsName>
53
- <dnsName>ec2-75-101-236-239.compute-1.amazonaws.com</dnsName>
54
- <reason/>
55
- <keyName>pjc-keypair</keyName>
56
- <amiLaunchIndex>0</amiLaunchIndex>
57
- <productCodes/>
58
- <instanceType>m1.small</instanceType>
59
- <launchTime>2008-06-26T21:55:55.000Z</launchTime>
60
- <placement>
61
- <availabilityZone>us-east-1c</availabilityZone>
62
- </placement>
63
- <kernelId>aki-a71cf9ce</kernelId>
64
- <ramdiskId>ari-a51cf9cc</ramdiskId>
65
- </item>
66
- </instancesSet>
67
- </item>
68
- </reservationSet>
69
- </DescribeInstancesResponse>
@@ -1,37 +0,0 @@
1
- <?xml version="1.0"?>
2
- <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01/">
3
- <reservationSet>
4
- <item>
5
- <reservationId>r-ec8d4085</reservationId>
6
- <ownerId>161964561164</ownerId>
7
- <groupSet>
8
- <item>
9
- <groupId>default</groupId>
10
- </item>
11
- </groupSet>
12
- <instancesSet>
13
- <item>
14
- <instanceId>i-94f82efd</instanceId>
15
- <imageId>ami-4bb05422</imageId>
16
- <instanceState>
17
- <code>16</code>
18
- <name>running</name>
19
- </instanceState>
20
- <privateDnsName>ip-10-251-203-148.ec2.internal</privateDnsName>
21
- <dnsName>ec2-75-101-205-180.compute-1.amazonaws.com</dnsName>
22
- <reason/>
23
- <keyName>auser</keyName>
24
- <amiLaunchIndex>0</amiLaunchIndex>
25
- <productCodes/>
26
- <instanceType>m1.small</instanceType>
27
- <launchTime>2008-06-27T02:25:26.000Z</launchTime>
28
- <placement>
29
- <availabilityZone>us-east-1a</availabilityZone>
30
- </placement>
31
- <kernelId>aki-a71cf9ce</kernelId>
32
- <ramdiskId>ari-a51cf9cc</ramdiskId>
33
- </item>
34
- </instancesSet>
35
- </item>
36
- </reservationSet>
37
- </DescribeInstancesResponse>
@@ -1,57 +0,0 @@
1
- module PoolParty
2
- module Ec2Wrapper
3
- module InstanceMethods
4
- def ec2
5
- @ec2 ||= EC2::Base.new(:access_key_id => "access", :secret_access_key => "shhhh")
6
- end
7
- end
8
- end
9
- class Master
10
- def launch_new_instance!
11
- letter = ("a".."z").to_a[instances.size] # For unique instance_ids
12
- h = {:instance_id => "i-58ba56#{letter}", :ip => "ip-127-0-0-1.aws.amazonaws.com", :status => "pending", :keypair => "alist", :launching_time => Time.now }
13
- instances << h
14
- Thread.new {wait 0.01;h[:status] = "running"} # Simulate the startup time
15
- return h
16
- end
17
- # Shutdown the instance by instance_id
18
- def terminate_instance!(instance_id)
19
- instances.select {|a| a[:instance_id] == instance_id}[0][:status] = "terminating"
20
- end
21
- # Instance description
22
- def describe_instance(id)
23
- item = instances.select {|a| a[:instance_id] == id}[0]
24
- EC2ResponseObject.get_hash_from_response(item)
25
- end
26
- # Get instance by id
27
- def get_instance_by_id(id)
28
- get_instances_description.select {|a| a.instance_id == id}[0] rescue nil
29
- end
30
- # Get the s3 description for the response in a hash format
31
- def get_instances_description
32
- instances
33
- end
34
- def get_non_empty_instances_description
35
- EC2::Response.parse(:xml => open("#{File.dirname(__FILE__)}/../files/response.txt").read)
36
- end
37
- # Fake the ec2 connection
38
- def ec2
39
- @ec2 ||= EC2::Base.new(:access_key_id => "not a key", :secret_access_key => "not a key")
40
- end
41
- # Some basic instances, not totally necessary
42
- def instances
43
- @instances ||= []
44
- end
45
- end
46
- class RemoteInstance
47
- def ssh(l="")
48
- "true"
49
- end
50
- def scp(s,d,o={})
51
- "true"
52
- end
53
- def run(s)
54
- "true"
55
- end
56
- end
57
- end
@@ -1,26 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Hash" do
4
- it "should preserve the contents of the original hash when safe_merge'ing" do
5
- a = {:a => "10", :b => "20"}
6
- b = {:b => "30", :c => "40"}
7
- a.safe_merge(b).should == {:a => "10", :b => "20", :c => "40"}
8
- end
9
- it "should preserve the contents of the original hash when safe_merge!'ing" do
10
- a = {:a => "10", :b => "20"}
11
- b = {:b => "30", :c => "40"}
12
- a.safe_merge!(b)
13
- a.should == {:a => "10", :b => "20", :c => "40"}
14
- end
15
- end
16
- describe "String" do
17
- before(:each) do
18
- @str =<<-EOS
19
- echo 'hi'
20
- puts 'hi'
21
- EOS
22
- end
23
- it "should be able to convert a big string with \n to a runnable string" do
24
- @str.runnable.should == "echo 'hi' && puts 'hi'"
25
- end
26
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Kernel extensions" do
4
- before(:each) do
5
- @host = Master.new
6
- end
7
- it "should eval the string into time" do
8
- @host.should_receive(:sleep).once.and_return true
9
- @host.wait "10.seconds"
10
- end
11
- end
12
- describe "Object extensions" do
13
- before(:each) do
14
- @klass = Object.new
15
- @klass.instance_eval <<-EOE
16
- def hello
17
- puts "hello"
18
- end
19
- EOE
20
- end
21
- it "should be able to get a list of the defined methods on the object" do
22
- @klass.my_methods.should == ["hello"]
23
- end
24
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "String" do
4
- before(:each) do
5
- @string = "string"
6
- @string.stub!(:bucket_objects).and_return([])
7
- end
8
- # Dumb test
9
- it "should be able to call bucket_objects on itself" do
10
- @string.should_receive(:bucket_objects)
11
- @string.bucket_objects
12
- end
13
- describe "with config replacements" do
14
- it "should replace those syms in the string" do
15
- ("new :port" ^ {:port => 100}).should == "new 100"
16
- end
17
- it "should be able to detect vars" do
18
- @string=<<-EOC
19
- listen web_proxy 127.0.0.1::client_port
20
- \tserver web1 127.0.0.1::port weight 1 minconn 3 maxconn 6 check inter 30000
21
- EOC
22
- (@string ^ {:client_port => 3000, :port => 3001}).should ==<<-EOO
23
- listen web_proxy 127.0.0.1:3000
24
- \tserver web1 127.0.0.1:3001 weight 1 minconn 3 maxconn 6 check inter 30000
25
- EOO
26
- end
27
- end
28
- end
@@ -1,213 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- class TestCallbacks
4
- include Callbacks
5
- attr_reader :str
6
-
7
- before :world, :hello
8
- after :world, :thanks
9
-
10
- def hello(caller)
11
- string << "hello "
12
- end
13
- def world
14
- string << "world"
15
- end
16
- def thanks(caller)
17
- string << ", thank you"
18
- end
19
- after :pop, :boom
20
- def pop
21
- string << "pop"
22
- end
23
- def boom(caller)
24
- string << " goes boom"
25
- end
26
- def string
27
- @str ||= String.new
28
- end
29
- end
30
- describe "Callbacks" do
31
- before(:each) do
32
- @klass = TestCallbacks.new
33
- end
34
- it "should retain it's class identifier" do
35
- @klass.class.should == TestCallbacks
36
- end
37
- it "should callback the method before the method runs" do
38
- @klass.world.should == "hello world, thank you"
39
- end
40
- it "should callback the method before the method runs" do
41
- @klass.pop.should == "pop goes boom"
42
- end
43
- end
44
- class TestMultipleCallbacks
45
- include Callbacks
46
- attr_reader :str
47
- def hi(caller)
48
- string << "hi, "
49
- end
50
- def hello(caller)
51
- string << "hello "
52
- end
53
- def world
54
- string << "world"
55
- end
56
- def string
57
- @str ||= String.new
58
- end
59
- before :world, :hi, :hello
60
- end
61
- describe "Multiple callbacks" do
62
- before(:each) do
63
- @klass = TestMultipleCallbacks.new
64
- end
65
- it "should be able to have multiple callbacks on the same call" do
66
- @klass.world.should == "hi, hello world"
67
- end
68
- end
69
- class OutsideClass
70
- def self.hello(caller)
71
- "hello"
72
- end
73
- end
74
- class TestOutsideClass
75
- include Callbacks
76
- before :world, {:hello => OutsideClass}
77
- def world
78
- "world"
79
- end
80
- end
81
- describe "Options" do
82
- before(:each) do
83
- @c = TestOutsideClass.new
84
- end
85
- it "should be able to pass external class options to the callback" do
86
- OutsideClass.should_receive(:hello).and_return "hello"
87
- @c.world
88
- end
89
- end
90
- class BlockClass
91
- include Callbacks
92
- before :world do
93
- string << "hello "
94
- end
95
- def world
96
- string << "world"
97
- end
98
- def string
99
- @string ||= ""
100
- end
101
- end
102
- describe "Block callbacks" do
103
- it "should call the block on the callback" do
104
- BlockClass.new.world.should == "hello world"
105
- end
106
- end
107
- class BlockAndMethodClass
108
- include Callbacks
109
- before :world, :hi do
110
- string << "hello "
111
- end
112
- def world
113
- string << "world"
114
- end
115
- def hi(caller)
116
- string << "hi, "
117
- end
118
- def string
119
- @string ||= ""
120
- end
121
- end
122
- describe "Block and method callbacks" do
123
- it "should call the block on the callback and add the block" do
124
- BlockAndMethodClass.new.world.should == "hi, hello world"
125
- end
126
- end
127
- class ExternalMethodCallClass
128
- include Callbacks
129
- before :world, :hello
130
- after :hello, :peter
131
-
132
- def world
133
- string << "world"
134
- end
135
- def hello(caller)
136
- string << "hello "
137
- end
138
- def peter(caller)
139
- string << "peter "
140
- end
141
- def string
142
- @string ||= ""
143
- end
144
- end
145
- describe "External method callbacks inside a method" do
146
- it "should call the block on the callback and add the " do
147
- ExternalMethodCallClass.new.world.should == "hello peter world"
148
- end
149
- end
150
- class OutsideBindingClass
151
- def hello(caller)
152
- caller.string << "hello"
153
- end
154
- end
155
- class BindingClass
156
- include Callbacks
157
- before :world, :hello => "OutsideBindingClass"
158
- def world
159
- string << "#{@hello} world"
160
- end
161
- def string
162
- @string ||= ""
163
- end
164
- end
165
- describe "Methods" do
166
- it "should have access to the local variables of the call" do
167
- BindingClass.new.world.should == "hello world"
168
- end
169
- end
170
- class EvilOutsideClass
171
- attr_reader :name
172
- def get_name(caller)
173
- @name = caller.hello
174
- end
175
- def show_name(caller)
176
- @name
177
- end
178
- end
179
- class BindingClass
180
- include Callbacks
181
- before :print, :get_name => "EvilOutsideClass"
182
- def print
183
- "hello"
184
- end
185
- def hello
186
- "franke"
187
- end
188
- end
189
- describe "Variables on the plugin callbacker class" do
190
- it "should have a new method of the class" do
191
- BindingClass.new.print
192
- BindingClass.new.methods.include?("eviloutsideclass").should == true
193
- end
194
- end
195
- class DoubleClass
196
- include Callbacks
197
- before :print, :hello => "OutsideBindingClass"
198
- after :print, :hello => "OutsideBindingClass"
199
-
200
- def print
201
- string
202
- end
203
- def string
204
- @string ||= ""
205
- end
206
- end
207
- describe "Chaining" do
208
- it "should be able to call both a before and an after spec" do
209
- @d = DoubleClass.new
210
- @d.print
211
- @d.string.should == "hellohello"
212
- end
213
- end