poolparty 0.0.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/License.txt +20 -0
- data/Manifest.txt +203 -0
- data/PostInstall.txt +18 -0
- data/README.txt +21 -82
- data/Rakefile +25 -18
- data/bin/cloud +31 -0
- data/bin/cloud-add-keypair +23 -0
- data/bin/cloud-configure +31 -0
- data/bin/cloud-contract +27 -0
- data/bin/cloud-expand +27 -0
- data/bin/cloud-list +32 -0
- data/bin/cloud-maintain +36 -0
- data/bin/cloud-osxcopy +22 -0
- data/bin/cloud-provision +31 -0
- data/bin/cloud-refresh +26 -0
- data/bin/cloud-ssh +18 -0
- data/bin/cloud-start +32 -0
- data/bin/cloud-terminate +23 -0
- data/bin/pool +25 -27
- data/bin/pool-console +12 -0
- data/bin/pool-describe +9 -0
- data/bin/pool-list +28 -0
- data/bin/pool-provision +34 -0
- data/bin/pool-spec +17 -0
- data/bin/pool-start +32 -0
- data/bin/pool-start-monitor +1 -0
- data/config/hoe.rb +115 -0
- data/config/requirements.rb +15 -0
- data/examples/basic.rb +20 -0
- data/examples/plugin_without_plugin_directory.rb +13 -0
- data/examples/poolparty.rb +12 -0
- data/examples/with_apache_plugin.rb +22 -0
- data/generators/poolspec/USAGE +5 -0
- data/generators/poolspec/poolspec_generator.rb +65 -0
- data/generators/poolspec/templates/pool_spec_template.erb +9 -0
- data/lib/erlang/eb_server.erl +27 -0
- data/lib/poolparty.rb +56 -0
- data/lib/poolparty/base_packages/haproxy.rb +42 -0
- data/lib/poolparty/base_packages/heartbeat.rb +45 -0
- data/lib/poolparty/base_packages/poolparty.rb +36 -0
- data/lib/poolparty/base_packages/ruby.rb +43 -0
- data/lib/poolparty/core/array.rb +24 -0
- data/lib/{core → poolparty/core}/exception.rb +0 -0
- data/lib/poolparty/core/float.rb +13 -0
- data/lib/poolparty/core/hash.rb +29 -0
- data/lib/poolparty/core/kernel.rb +37 -0
- data/lib/{core → poolparty/core}/module.rb +18 -0
- data/lib/poolparty/core/my_open_struct.rb +18 -0
- data/lib/poolparty/core/object.rb +54 -0
- data/lib/poolparty/core/proc.rb +7 -0
- data/lib/poolparty/core/string.rb +72 -0
- data/lib/poolparty/core/symbol.rb +8 -0
- data/lib/{core → poolparty/core}/time.rb +15 -0
- data/lib/poolparty/exceptions/RemoteException.rb +12 -0
- data/lib/poolparty/exceptions/ResourceException.rb +7 -0
- data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
- data/lib/poolparty/exceptions/SpecException.rb +7 -0
- data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
- data/lib/poolparty/helpers/binary.rb +31 -0
- data/lib/poolparty/helpers/console.rb +30 -0
- data/lib/poolparty/helpers/display.rb +34 -0
- data/lib/poolparty/helpers/optioner.rb +64 -0
- data/lib/poolparty/helpers/provisioner_base.rb +250 -0
- data/lib/poolparty/helpers/provisioners/master.rb +136 -0
- data/lib/poolparty/helpers/provisioners/slave.rb +44 -0
- data/lib/poolparty/modules/cloud_resourcer.rb +89 -0
- data/lib/poolparty/modules/configurable.rb +34 -0
- data/lib/poolparty/modules/definable_resource.rb +59 -0
- data/lib/poolparty/modules/file_writer.rb +55 -0
- data/lib/poolparty/modules/method_missing_sugar.rb +53 -0
- data/lib/poolparty/modules/output.rb +13 -0
- data/lib/poolparty/modules/pretty_printer.rb +39 -0
- data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -22
- data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
- data/lib/poolparty/monitors/base_monitor.rb +16 -0
- data/lib/poolparty/net/remote.rb +35 -0
- data/lib/poolparty/net/remote_bases/ec2.rb +148 -0
- data/lib/poolparty/net/remote_instance.rb +69 -0
- data/lib/poolparty/net/remoter.rb +224 -0
- data/lib/poolparty/net/remoter_base.rb +117 -0
- data/lib/poolparty/plugins/gem_package.rb +17 -0
- data/lib/poolparty/plugins/git.rb +41 -0
- data/lib/poolparty/plugins/line.rb +76 -0
- data/lib/poolparty/plugins/svn.rb +48 -0
- data/lib/poolparty/pool/base.rb +75 -0
- data/lib/poolparty/pool/cloud.rb +164 -0
- data/lib/poolparty/pool/custom_resource.rb +61 -0
- data/lib/poolparty/pool/loggable.rb +29 -0
- data/lib/poolparty/pool/plugin.rb +41 -0
- data/lib/poolparty/pool/plugin_model.rb +48 -0
- data/lib/poolparty/pool/pool.rb +55 -0
- data/lib/poolparty/pool/resource.rb +248 -0
- data/lib/poolparty/pool/resources/class_package.rb +64 -0
- data/lib/poolparty/pool/resources/conditional.rb +41 -0
- data/lib/poolparty/pool/resources/cron.rb +14 -0
- data/lib/poolparty/pool/resources/directory.rb +23 -0
- data/lib/poolparty/pool/resources/exec.rb +26 -0
- data/lib/poolparty/pool/resources/file.rb +23 -0
- data/lib/poolparty/pool/resources/gem.rb +14 -0
- data/lib/poolparty/pool/resources/host.rb +14 -0
- data/lib/poolparty/pool/resources/package.rb +14 -0
- data/lib/poolparty/pool/resources/remote_file.rb +22 -0
- data/lib/poolparty/pool/resources/service.rb +21 -0
- data/lib/poolparty/pool/resources/sshkey.rb +19 -0
- data/lib/poolparty/pool/resources/variable.rb +27 -0
- data/lib/poolparty/pool/script.rb +44 -0
- data/lib/poolparty/templates/authkeys +2 -0
- data/{config/monit/nginx.monit.conf → lib/poolparty/templates/cib.xml} +0 -0
- data/lib/poolparty/templates/fileserver.conf +4 -0
- data/lib/poolparty/templates/gem +25 -0
- data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -2
- data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
- data/lib/poolparty/templates/namespaceauth.conf +19 -0
- data/lib/poolparty/templates/puppet.conf +17 -0
- data/lib/poolparty/version.rb +9 -0
- data/lib/poolpartycl.rb +3 -0
- data/poolparty.gemspec +56 -47
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/poolparty/base_packages/haproxy_spec.rb +13 -0
- data/spec/poolparty/base_packages/heartbeat_spec.rb +30 -0
- data/spec/poolparty/bin/console_spec.rb +80 -0
- data/spec/poolparty/core/array_spec.rb +26 -0
- data/spec/poolparty/core/float.rb +13 -0
- data/spec/poolparty/core/hash_spec.rb +63 -0
- data/spec/poolparty/core/kernel_spec.rb +24 -0
- data/spec/poolparty/core/module_spec.rb +15 -0
- data/spec/poolparty/core/object_spec.rb +40 -0
- data/spec/poolparty/core/string_spec.rb +152 -0
- data/spec/poolparty/core/time_spec.rb +52 -0
- data/spec/poolparty/helpers/binary_spec.rb +26 -0
- data/spec/poolparty/helpers/display_spec.rb +13 -0
- data/spec/poolparty/helpers/optioner_spec.rb +39 -0
- data/spec/poolparty/helpers/provisioner_base_spec.rb +121 -0
- data/spec/poolparty/helpers/provisioners/master_spec.rb +54 -0
- data/spec/poolparty/helpers/provisioners/slave_spec.rb +28 -0
- data/spec/poolparty/modules/cloud_resourcer_spec.rb +135 -0
- data/spec/poolparty/modules/configurable_spec.rb +26 -0
- data/spec/poolparty/modules/definable_resource.rb +9 -0
- data/spec/poolparty/modules/file_writer_spec.rb +49 -0
- data/spec/poolparty/modules/s3_string_spec.rb +15 -0
- data/spec/poolparty/modules/tmp/willy/nilly.rb +1 -0
- data/spec/poolparty/net/remote_bases/ec2_spec.rb +92 -0
- data/spec/poolparty/net/remote_instance_spec.rb +70 -0
- data/spec/poolparty/net/remote_spec.rb +286 -0
- data/spec/poolparty/net/remoter_base_spec.rb +80 -0
- data/spec/poolparty/net/remoter_spec.rb +191 -0
- data/spec/poolparty/plugins/git_spec.rb +33 -0
- data/spec/poolparty/plugins/line_spec.rb +16 -0
- data/spec/poolparty/plugins/svn_spec.rb +16 -0
- data/spec/poolparty/pool/base_spec.rb +108 -0
- data/spec/poolparty/pool/cloud_spec.rb +299 -0
- data/spec/poolparty/pool/configurers/files/ruby_basic.rb +17 -0
- data/spec/poolparty/pool/configurers/files/ruby_plugins.rb +16 -0
- data/spec/poolparty/pool/configurers/ruby_spec.rb +58 -0
- data/spec/poolparty/pool/custom_resource_spec.rb +115 -0
- data/spec/poolparty/pool/example_spec.rb +112 -0
- data/spec/poolparty/pool/plugin_model_spec.rb +63 -0
- data/spec/poolparty/pool/plugin_spec.rb +85 -0
- data/spec/poolparty/pool/pool_spec.rb +83 -0
- data/spec/poolparty/pool/resource_spec.rb +224 -0
- data/spec/poolparty/pool/resources/class_package_spec.rb +84 -0
- data/spec/poolparty/pool/resources/conditional_spec.rb +38 -0
- data/spec/poolparty/pool/resources/cron_spec.rb +49 -0
- data/spec/poolparty/pool/resources/directory_spec.rb +40 -0
- data/spec/poolparty/pool/resources/exec_spec.rb +37 -0
- data/spec/poolparty/pool/resources/file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/gem_spec.rb +16 -0
- data/spec/poolparty/pool/resources/host_spec.rb +28 -0
- data/spec/poolparty/pool/resources/package_spec.rb +44 -0
- data/spec/poolparty/pool/resources/remote_file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/service_spec.rb +45 -0
- data/spec/poolparty/pool/resources/sshkey_spec.rb +48 -0
- data/spec/poolparty/pool/resources/variable_spec.rb +20 -0
- data/spec/poolparty/pool/script_spec.rb +51 -0
- data/spec/poolparty/pool/test_plugins/sshkey_test +2 -0
- data/{test/test_pool_party.rb → spec/poolparty/pool/test_plugins/virtual_host_template.erb} +0 -0
- data/spec/poolparty/pool/test_plugins/webserver.rb +46 -0
- data/spec/poolparty/poolparty_spec.rb +33 -0
- data/spec/poolparty/spec_helper.rb +120 -0
- data/tasks/cloud.rake +57 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/development.rake +78 -0
- data/tasks/ec2.rake +20 -0
- data/tasks/environment.rake +7 -0
- data/tasks/instance.rake +63 -0
- data/tasks/server.rake +42 -0
- data/tasks/spec.rake +17 -0
- data/tasks/website.rake +17 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +2 -0
- data/test/test_pool_spec_generator.rb +47 -0
- data/test/test_poolparty.rb +11 -0
- data/test_manifest.pp +538 -0
- data/website/index.html +107 -0
- data/website/index.txt +95 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/code.css +29 -0
- data/website/stylesheets/screen.css +147 -0
- data/website/template.html.erb +49 -0
- metadata +282 -101
- data/CHANGELOG +0 -4
- data/Manifest +0 -55
- data/bin/instance +0 -54
- data/config/config.yml +0 -23
- data/config/create_proxy_ami.sh +0 -582
- data/config/heartbeat_authkeys.conf +0 -2
- data/config/monit.conf +0 -8
- data/config/monit/haproxy.monit.conf +0 -7
- data/config/nginx.conf +0 -24
- data/lib/core/array.rb +0 -10
- data/lib/core/kernel.rb +0 -9
- data/lib/core/object.rb +0 -14
- data/lib/modules/callback.rb +0 -55
- data/lib/modules/ec2_wrapper.rb +0 -74
- data/lib/pool_party.rb +0 -69
- data/lib/pool_party/application.rb +0 -133
- data/lib/pool_party/init.rb +0 -4
- data/lib/pool_party/master.rb +0 -189
- data/lib/pool_party/monitors.rb +0 -13
- data/lib/pool_party/monitors/cpu.rb +0 -18
- data/lib/pool_party/monitors/memory.rb +0 -21
- data/lib/pool_party/monitors/web.rb +0 -18
- data/lib/pool_party/optioner.rb +0 -16
- data/lib/pool_party/os.rb +0 -11
- data/lib/pool_party/os/ubuntu.rb +0 -78
- data/lib/pool_party/remote_instance.rb +0 -180
- data/lib/pool_party/remoting.rb +0 -112
- data/lib/pool_party/scheduler.rb +0 -93
- data/lib/pool_party/tasks.rb +0 -220
- data/lib/s3/s3_object_store_folders.rb +0 -44
- data/spec/application_spec.rb +0 -32
- data/spec/callback_spec.rb +0 -65
- data/spec/helpers/ec2_mock.rb +0 -56
- data/spec/helpers/remote_instance_mock.rb +0 -11
- data/spec/kernel_spec.rb +0 -11
- data/spec/master_spec.rb +0 -147
- data/spec/monitor_spec.rb +0 -16
- data/spec/optioner_spec.rb +0 -22
- data/spec/poolparty_spec.rb +0 -8
- data/spec/remote_instance_spec.rb +0 -29
- data/spec/remoting_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -38
- data/spec/string_spec.rb +0 -28
@@ -0,0 +1,42 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Base
|
3
|
+
plugin :haproxy do
|
4
|
+
|
5
|
+
def enable
|
6
|
+
execute_if("$hostname", "master") do
|
7
|
+
package({:name => "haproxy"})
|
8
|
+
|
9
|
+
# Startup haproxy and enable it
|
10
|
+
has_line_in_file("ENABLED=1", "/etc/default/haproxy")
|
11
|
+
has_line_in_file("SYSLOGD=\"-r\"", "/etc/default/syslogd")
|
12
|
+
has_line_in_file("local0.* /var/log/haproxy.log", "/etc/syslog.conf", {:notify => 'Service["sysklogd"]'})
|
13
|
+
|
14
|
+
# Restart sysklogd after we update the haproxy.log
|
15
|
+
has_service(:name => "sysklogd") do
|
16
|
+
ensures "running"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Service is required
|
20
|
+
has_service(:name => "haproxy")
|
21
|
+
|
22
|
+
# Tempalte variables
|
23
|
+
variable(:name => "name_haproxy", :value => "#{@parent.name}")
|
24
|
+
variable(:name => "nodenames_haproxy", :value => list_of_node_names)
|
25
|
+
variable(:name => "node_ips_haproxy", :value => list_of_node_ips)
|
26
|
+
variable(:name => "ports_haproxy", :value => ([(self.respond_to?(:port) ? port : Base.port)].flatten))
|
27
|
+
variable(:name => "forwarding_port", :value => (respond_to?(:forwarding_port) ? forwarding_port : Base.forwarding_port))
|
28
|
+
variable(:name => "proxy_mode", :value => (respond_to?(:proxy_mode) ? proxy_mode : Base.proxy_mode))
|
29
|
+
|
30
|
+
# These can also be passed in via hash
|
31
|
+
has_remotefile(:name => "/etc/haproxy.cfg") do
|
32
|
+
mode 644
|
33
|
+
# onlyif '$hostname == "master"'
|
34
|
+
requires 'Package["haproxy"]'
|
35
|
+
notify 'Service["haproxy"]'
|
36
|
+
template File.join(File.dirname(__FILE__), "..", "templates/haproxy.conf")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Base
|
3
|
+
plugin :heartbeat do
|
4
|
+
|
5
|
+
def enable
|
6
|
+
execute_if("$hostname", "master") do
|
7
|
+
has_package(:name => "heartbeat-2", :ensure => "installed")
|
8
|
+
has_service(:name => "heartbeat", :hasstatus => true) do
|
9
|
+
ensures "running"
|
10
|
+
end
|
11
|
+
|
12
|
+
has_exec(:name => "heartbeat-update-cib", :command => "/usr/sbin/cibadmin -R -x /etc/ha.d/cib.xml", :refreshonly => true)
|
13
|
+
|
14
|
+
# variables for the templates
|
15
|
+
has_variable({:name => "ha_nodenames", :value => list_of_node_names})
|
16
|
+
has_variable({:name => "ha_node_ips", :value => list_of_node_ips})
|
17
|
+
has_variable({:name => "ha_port", :value => (self.respond_to?(:port) ? port : Base.port)})
|
18
|
+
|
19
|
+
# These can also be passed in via hash
|
20
|
+
has_remotefile(:name => "/etc/ha.d/ha.cf") do
|
21
|
+
mode 444
|
22
|
+
requires 'Package["heartbeat-2"]'
|
23
|
+
notify 'Service["heartbeat"]'
|
24
|
+
template File.join(File.dirname(__FILE__), "..", "templates/ha.cf")
|
25
|
+
end
|
26
|
+
|
27
|
+
has_remotefile(:name => "/etc/ha.d/authkeys") do
|
28
|
+
mode 400
|
29
|
+
requires 'Package["heartbeat-2"]'
|
30
|
+
notify 'Service["heartbeat"]'
|
31
|
+
template File.join(File.dirname(__FILE__), "..", "templates/authkeys")
|
32
|
+
end
|
33
|
+
|
34
|
+
has_remotefile(:name => "/etc/ha.d/cib.xml") do
|
35
|
+
mode 444
|
36
|
+
requires 'Package["heartbeat-2"]'
|
37
|
+
notify 'Exec["heartbeat-update-cib"]'
|
38
|
+
template File.join(File.dirname(__FILE__), "..", "templates/cib.xml")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Base
|
3
|
+
plugin :poolparty do
|
4
|
+
|
5
|
+
def enable
|
6
|
+
has_package(:name => "erlang")
|
7
|
+
# These should be installed automagically by poolparty, but just in case
|
8
|
+
with_options(:requires => 'Package["update-rubygems"]') do
|
9
|
+
has_gempackage(:name => "open4")
|
10
|
+
has_gempackage(:name => "parsetree")
|
11
|
+
has_gempackage(:name => "rubyinline")
|
12
|
+
has_gempackage(:name => "activesupport")
|
13
|
+
has_gempackage(:name => "logging")
|
14
|
+
has_gempackage(:name => "hoe")
|
15
|
+
has_gempackage(:name => "xml-simple")
|
16
|
+
has_gempackage(:name => "ruby2ruby")
|
17
|
+
|
18
|
+
has_gempackage(:name => "grempe-amazon-ec2", :source => "http://gems.github.com", :requires => 'Package["xml-simple"]')
|
19
|
+
has_gempackage(:name => "auser-poolparty", :source => "http://gems.github.com", :requires => 'Package["activesupport", "logging", "hoe", "open4"]')
|
20
|
+
end
|
21
|
+
# Build hostsfile
|
22
|
+
# TODO: COME BACK AND CLEAN THIS UP
|
23
|
+
(self.respond_to?(:list_of_running_instances) ? self : parent).list_of_running_instances.each do |ri|
|
24
|
+
has_host({:name => "#{ri.name}", :ip => ri.ip })
|
25
|
+
end
|
26
|
+
|
27
|
+
cron({:command => "cloud-maintain"}) do
|
28
|
+
minute "*/5"
|
29
|
+
user "puppet"
|
30
|
+
end
|
31
|
+
# has_host(:name => "puppet", :ip => (self.respond_to?(:master) ? self : parent).master.ip)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Base
|
3
|
+
plugin :ruby do
|
4
|
+
|
5
|
+
def enable
|
6
|
+
install_base_packages
|
7
|
+
end
|
8
|
+
|
9
|
+
def install_base_packages
|
10
|
+
has_package(:name => "libreadline-ruby1.8")
|
11
|
+
has_package(:name => "libruby1.8")
|
12
|
+
has_package(:name => "ruby1.8-dev")
|
13
|
+
has_package(:name => "ruby1.8")
|
14
|
+
has_package(:name => "rubygems")
|
15
|
+
|
16
|
+
has_line_in_file("export PATH=$PATH:/var/lib/gems/1.8/bin/", "/etc/profile")
|
17
|
+
|
18
|
+
# exec(:name => "update-rubygems") do
|
19
|
+
# command "gem update --system"
|
20
|
+
# onlyif "gem -v | grep 1."
|
21
|
+
# notify 'Exec["fix-updated-rubygems"]'
|
22
|
+
# end
|
23
|
+
# exec(:name => "fix-updated-rubygems") do
|
24
|
+
# command "awk \'{print} NR == 9 {print \"require \"rubygems/gem_runner\"\"}\' /usr/bin/gem"
|
25
|
+
# ifnot "awk \"/gem_runner/\" /usr/bin/gem"
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
|
29
|
+
def enable_ri
|
30
|
+
has_package(:name => "ri1.8")
|
31
|
+
end
|
32
|
+
|
33
|
+
def enable_irb
|
34
|
+
has_package(:name => "irb1.8")
|
35
|
+
end
|
36
|
+
|
37
|
+
def enable_rdoc
|
38
|
+
has_package(:name => "rdoc1.8")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Array extensions
|
3
|
+
=end
|
4
|
+
require "enumerator"
|
5
|
+
class Array
|
6
|
+
def to_os
|
7
|
+
map {|a| a.to_os }
|
8
|
+
end
|
9
|
+
def collect_with_index &block
|
10
|
+
self.enum_for(:each_with_index).collect &block
|
11
|
+
end
|
12
|
+
def runnable(quiet=true)
|
13
|
+
self.join(" \n ").runnable(quiet)
|
14
|
+
end
|
15
|
+
def nice_runnable(quiet=true)
|
16
|
+
self.flatten.reject{|e| (e.nil? || e.empty?) }.join(" \n ").chomp.nice_runnable(quiet)
|
17
|
+
end
|
18
|
+
def to_string(prev="")
|
19
|
+
map {|a| a.to_string(prev)}.join("\n")
|
20
|
+
end
|
21
|
+
def get_named(str="")
|
22
|
+
map {|a| a.name == str ? a : nil }.reject {|a| a.nil? }
|
23
|
+
end
|
24
|
+
end
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Hash extentions
|
3
|
+
=end
|
4
|
+
class Hash
|
5
|
+
alias :old_select :select
|
6
|
+
|
7
|
+
def select(&block)
|
8
|
+
Hash[*self.old_select(&block).inject([]){|res,(k,v)| res << k << v}]
|
9
|
+
end
|
10
|
+
def extract!(&block)
|
11
|
+
o = select(&block)
|
12
|
+
o.keys.each {|k| self.delete(k) }
|
13
|
+
o
|
14
|
+
end
|
15
|
+
def safe_merge(other_hash)
|
16
|
+
merge(other_hash.delete_if {|k,v| has_key?(k) })
|
17
|
+
end
|
18
|
+
def safe_merge!(other_hash)
|
19
|
+
merge!(other_hash.delete_if {|k,v| has_key?(k) && !v.nil? })
|
20
|
+
end
|
21
|
+
def flush_out(prev="", post="")
|
22
|
+
map {|k,v| "#{prev}#{k} => #{v.to_option_string}#{post}"}
|
23
|
+
end
|
24
|
+
def to_os
|
25
|
+
m={}
|
26
|
+
each {|k,v| m[k] = v.to_os }
|
27
|
+
MyOpenStruct.new(m)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Kernel overloads
|
3
|
+
=end
|
4
|
+
module Kernel
|
5
|
+
# Nice wait instead of sleep
|
6
|
+
def wait(time=5)
|
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
|
+
def load_p(dir)
|
13
|
+
Dir["#{dir}/*.rb"].each do |file|
|
14
|
+
require "#{file}" if ::FileTest.file?(file)
|
15
|
+
end
|
16
|
+
Dir["#{dir}/*"].each do |dir|
|
17
|
+
load_p(dir) if ::FileTest.directory?(dir)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def with_warnings_suppressed
|
21
|
+
saved_verbosity = $-v
|
22
|
+
$-v = nil
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
$-v = saved_verbosity
|
26
|
+
end
|
27
|
+
def hide_output
|
28
|
+
begin
|
29
|
+
old_stdout = STDOUT.dup
|
30
|
+
STDOUT.reopen(File.open((PLATFORM =~ /mswin/ ? "NUL" : "/dev/null"), 'w'))
|
31
|
+
yield if block_given?
|
32
|
+
ensure
|
33
|
+
STDOUT.flush
|
34
|
+
STDOUT.reopen(old_stdout)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -19,4 +19,22 @@ class Module
|
|
19
19
|
private target
|
20
20
|
end
|
21
21
|
end
|
22
|
+
def attr_accessor_with_default( *syms, &block )
|
23
|
+
raise 'Default value in block required' unless block
|
24
|
+
syms.each do | sym |
|
25
|
+
module_eval do
|
26
|
+
attr_writer( sym )
|
27
|
+
define_method( sym ) do | |
|
28
|
+
class << self; self; end.class_eval do
|
29
|
+
attr_reader( sym )
|
30
|
+
end
|
31
|
+
instance_variables.include?("@#{sym}") ? instance_variable_get( "@#{sym}" ) : instance_variable_set( "@#{sym}", block.call )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
def set(*args)
|
38
|
+
end
|
39
|
+
alias_method :custom, :set
|
22
40
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Create an extended open struct
|
3
|
+
=end
|
4
|
+
require "ostruct"
|
5
|
+
class MyOpenStruct < OpenStruct
|
6
|
+
attr_accessor :keys
|
7
|
+
def initialize(h)
|
8
|
+
@keys = h.keys
|
9
|
+
super
|
10
|
+
end
|
11
|
+
def to_hash
|
12
|
+
m = {}
|
13
|
+
@keys.map do |key|
|
14
|
+
m.update( {key => self.send(key)} )
|
15
|
+
end
|
16
|
+
m
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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 to_os
|
10
|
+
self
|
11
|
+
end
|
12
|
+
def alias_method(new_id, original_id)
|
13
|
+
original = self.method(original_id).to_proc
|
14
|
+
define_method(new_id){|*args| original.call(*args)}
|
15
|
+
end
|
16
|
+
def with_options(opts={}, parent=self, &block)
|
17
|
+
@p = parent.clone
|
18
|
+
@p.options.merge!(opts)
|
19
|
+
@p.instance_eval &block if block
|
20
|
+
end
|
21
|
+
def returning(receiver)
|
22
|
+
yield receiver
|
23
|
+
receiver
|
24
|
+
end
|
25
|
+
def extended(&block)
|
26
|
+
block.in_context(self).call
|
27
|
+
self
|
28
|
+
end
|
29
|
+
def to_option_string
|
30
|
+
case self.class
|
31
|
+
when String
|
32
|
+
self.to_option_string
|
33
|
+
when Array
|
34
|
+
self.each {|a| a.to_option_string }.join(" ")
|
35
|
+
else
|
36
|
+
"#{self}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def block_instance_eval(*args, &block)
|
40
|
+
return instance_eval(*args,&block) unless block_given? && !block.arity.zero?
|
41
|
+
old_method = (self.class.instance_method(:__) rescue nil)
|
42
|
+
self.class.send(:define_method, :__, &block)
|
43
|
+
block_method = self.class.instance_method(:__)
|
44
|
+
if old_method
|
45
|
+
self.class.send(:define_method, :__, old_method)
|
46
|
+
else
|
47
|
+
self.class.send(:remove_method, :__)
|
48
|
+
end
|
49
|
+
block_method.bind(self).call(*args)
|
50
|
+
end
|
51
|
+
def meta_def name, &blk
|
52
|
+
(class << self; self; end).instance_eval { define_method name, &blk }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class String
|
2
|
+
def hasherize(format=[])
|
3
|
+
hash = {}
|
4
|
+
i = 0
|
5
|
+
self.split(%r{[\n|\t|\s| ]+}).map {|a| a.strip}.each do |f|
|
6
|
+
next unless format[i]
|
7
|
+
unless f == "" || f.nil?
|
8
|
+
hash[format[i].to_sym] = f
|
9
|
+
i+=1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
hash
|
13
|
+
end
|
14
|
+
def ^(h={})
|
15
|
+
self.gsub(/:([\w]+)/) {h[$1.to_sym] if h.include?($1.to_sym)}
|
16
|
+
end
|
17
|
+
def arrayable
|
18
|
+
self.strip.split(/\n/)
|
19
|
+
end
|
20
|
+
def runnable(quite=true)
|
21
|
+
# map {|l| l << "#{" >/dev/null 2>/dev/null" if quite}" }.
|
22
|
+
self.strip.split(/\n/).join(" && ")
|
23
|
+
end
|
24
|
+
def top_level_class
|
25
|
+
self.split("::")[-1].downcase rescue self
|
26
|
+
end
|
27
|
+
def sanitize
|
28
|
+
self.gsub(/[\.]*/, '')
|
29
|
+
end
|
30
|
+
def nice_runnable(quite=true)
|
31
|
+
self.split(/ && /).join("\n")
|
32
|
+
end
|
33
|
+
def to_option_string(ns=[])
|
34
|
+
a_template = (self =~ /template/) == 0
|
35
|
+
a_service = self =~ /^[A-Z][a-zA-Z]*\[[a-zA-Z0-9\-\.\"\'_\$\{\}\/]*\]/
|
36
|
+
(a_service || a_template) ? "#{self}" : "'#{self}'"
|
37
|
+
end
|
38
|
+
# Refactor this guy to get the class if the class is defined, and not always create a new one
|
39
|
+
# although, it doesn't really matter as ruby will just reopen the class
|
40
|
+
def class_constant(superclass=nil, opts={}, &block)
|
41
|
+
symc = ((opts && opts[:preserve]) ? ("#{self.classify}Classs") : "PoolParty#{self.classify}Classs").classify
|
42
|
+
|
43
|
+
kla=<<-EOE
|
44
|
+
class #{symc} #{"< #{superclass}" if superclass}
|
45
|
+
end
|
46
|
+
EOE
|
47
|
+
|
48
|
+
Kernel.module_eval kla
|
49
|
+
klass = symc.constantize
|
50
|
+
klass.module_eval &block if block
|
51
|
+
|
52
|
+
klass
|
53
|
+
end
|
54
|
+
|
55
|
+
def module_constant(&block)
|
56
|
+
symc = "#{self}_Module".classify
|
57
|
+
mod = Object.const_defined?(symc) ? Object.const_get(symc.to_sym) : Module.new(&block)
|
58
|
+
Object.const_set(symc, mod) unless Object.const_defined?(symc)
|
59
|
+
symc.to_s.constantize
|
60
|
+
end
|
61
|
+
def preserved_module_constant(ext="", from="PoolParty::", &block)
|
62
|
+
symc = "#{self}#{ext}".classify
|
63
|
+
mod = Kernel.const_defined?(symc) ? Kernel.const_get(symc.to_sym) : Module.new(&block)
|
64
|
+
Kernel.const_set(symc, mod) unless Kernel.const_defined?(symc)
|
65
|
+
symc.to_s.constantize
|
66
|
+
end
|
67
|
+
def collect_each_line_with_index(&block)
|
68
|
+
returning [] do |arr|
|
69
|
+
arr << self.split(/\n/).collect_with_index(&block)
|
70
|
+
end.flatten
|
71
|
+
end
|
72
|
+
end
|