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
@@ -0,0 +1,9 @@
1
+ # Basic poolparty template
2
+
3
+ pool :<%= name -%> do
4
+
5
+ cloud :app do
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,27 @@
1
+ %%%***************************************
2
+ %%%
3
+ %%% PoolParty node-server
4
+ %%% Author: Ari Lerner <ari.the.lerner@gmail.com>
5
+ %%%
6
+ %%% Description: This server runs on the poolparty nodes
7
+ %%%
8
+ %%%***************************************
9
+
10
+ % The name of our module
11
+ -module (eb_server).
12
+ % We are using the gen_server behaviour
13
+ -behaviour (gen_server).
14
+
15
+ % API methods
16
+ -export ([start_link/0]).
17
+
18
+ % gen_server callbacks
19
+ -export ([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
20
+
21
+ % Define the structure of the tuple state
22
+ -record (state, {}).
23
+ -define (SERVER, ?MODULE).
24
+
25
+ % API Methods
26
+ start_link() ->
27
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
data/lib/poolparty.rb CHANGED
@@ -1,131 +1,55 @@
1
- =begin rdoc
2
- The main file, contains the client and the server application methods
3
- =end
4
- $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
5
-
6
- $TRACE = true
7
-
8
- # rubygems
9
1
  require 'rubygems'
10
- require "aws/s3"
11
- require "EC2"
12
- require "aska"
13
- begin
14
- require 'crafterm-sprinkle'
15
- rescue LoadError
16
- require 'sprinkle'
17
- end
18
- require "pp"
19
- require "tempfile"
20
2
 
21
- begin
22
- require 'fastthread'
23
- require 'system_timer'
24
- @@timer = SystemTimer
25
- rescue LoadError
26
- require 'thread'
27
- require 'timeout'
28
- @@timer = Timeout
29
- end
3
+ # Load required gems
4
+ require 'active_support'
5
+ require 'open4'
6
+ require "ftools"
7
+ require "logging"
8
+
9
+ # Use active supports auto load mechanism
10
+ ActiveSupport::Dependencies.load_paths << File.dirname(__FILE__)
30
11
 
31
12
  ## Load PoolParty
32
- pwd = File.dirname(__FILE__)
13
+ require "#{File.dirname(__FILE__)}/poolparty/version"
33
14
 
34
- # Load the required files
35
- # If there is an init file, load that, otherwise
36
- # require all the files in each directory
37
- %w(core modules s3 helpers poolparty).each do |dir|
38
- Dir["#{pwd}/#{dir}"].each do |dir|
39
- begin
40
- require File.join(dir, "init")
41
- rescue LoadError => e
42
- Dir["#{pwd}/#{File.basename(dir)}/**"].each {|file| require File.join(dir, File.basename(file))}
43
- end
15
+ %w(core modules exceptions net).each do |dir|
16
+ Dir[File.dirname(__FILE__) + "/poolparty/#{dir}/**.rb"].each do |file|
17
+ require file
44
18
  end
45
19
  end
46
20
 
47
- module PoolParty
48
- class Version #:nodoc:
49
- @major = 0
50
- @minor = 1
51
- @tiny = 2
21
+ Kernel.load_p File.dirname(__FILE__) + "/poolparty/pool/**"
52
22
 
53
- def self.string
54
- [@major, @minor, @tiny].join('.')
55
- end
56
- end
57
- def timer
58
- @@timer
59
- end
60
- # PoolParty options
61
- def options(opts={})
62
- Application.options(opts)
63
- end
64
- # Are we working in verbose-mode
65
- def verbose?
66
- options.verbose == true
67
- end
68
- # Send a message if we are in verbose-mode
69
- def message(msg="")
70
- puts "-- #{msg}" if verbose?
71
- end
72
- # Root directory of the application
73
- def root_dir
74
- File.expand_path(File.dirname(__FILE__) + "/..")
75
- end
76
- # User directory
77
- def user_dir
78
- Application.working_directory
79
- end
80
- # Write string to a tempfile
81
- def write_to_temp_file(str="")
82
- tempfile = Tempfile.new("rand#{rand(1000)}-#{rand(1000)}")
83
- tempfile.print(str)
84
- tempfile.flush
85
- tempfile
86
- end
87
- def register_monitor(*names)
88
- names.each do |name|
89
- unless registered_monitor?(name)
90
- PoolParty::Monitors.extend name
91
-
92
- PoolParty::Master.send :include, name::Master
93
- PoolParty::RemoteInstance.send :include, name::Remote
94
-
95
- registered_monitors << name
96
- end
97
- end
98
- end
99
- def registered_monitor?(name); registered_monitors.include?(name); end
100
- def registered_monitors; @@registered_monitors ||= [];end
23
+ module PoolParty
24
+ include FileWriter
101
25
 
102
- def load_app
103
- load_monitors
104
- load_plugins
105
- end
106
- def load_monitors
107
- loc = File.directory?("#{user_dir}/monitors") ? "#{user_dir}/monitors" : "#{root_dir}/lib/poolparty/monitors"
108
- Dir["#{loc}/*"].each {|f| require f}
26
+ def logger
27
+ @pool_logger ||= make_new_logger
109
28
  end
110
29
 
111
- def load_plugins
112
- Dir["#{plugin_dir}/**/init.rb"].each {|a| require a} if File.directory?(plugin_dir)
113
- end
114
- def reset!
115
- @@registered_monitors = nil
116
- @@installed_plugins = nil
117
- end
118
- def plugin_dir
119
- "#{user_dir}/plugins"
120
- end
121
- def read_config_file(filename)
122
- return {} unless filename
123
- YAML.load(open(filename).read)
124
- end
125
- def include_cloud_tasks
126
- Tasks.new.define_tasks
30
+ private
31
+ #:nodoc:#
32
+ def make_new_logger
33
+ FileUtils.mkdir_p Base.pool_logger_location unless ::File.directory?(Base.pool_logger_location)
34
+ Loggable.new
127
35
  end
36
+ end
37
+
38
+ class Object
39
+ include PoolParty
40
+ include PoolParty::Pool
41
+ include PoolParty::Cloud
128
42
 
129
- alias_method :tasks, :include_cloud_tasks
130
- alias_method :include_tasks, :include_cloud_tasks
43
+ include PoolParty::DefinableResource
44
+ end
45
+
46
+ class Class
47
+ include PoolParty::PluginModel
48
+ end
49
+
50
+ ## Load PoolParty Plugins and package
51
+ %w(plugins base_packages).each do |dir|
52
+ Dir[File.dirname(__FILE__) + "/poolparty/#{dir}/**.rb"].each do |file|
53
+ require file
54
+ end
131
55
  end
@@ -0,0 +1,41 @@
1
+ module PoolParty
2
+ class Base
3
+ plugin :haproxy do
4
+
5
+ def enable
6
+ package({:name => "haproxy"})
7
+
8
+ # Startup haproxy and enable it
9
+ has_line_in_file("ENABLED=1", "/etc/default/haproxy")
10
+ has_line_in_file("SYSLOGD=\"-r\"", "/etc/default/syslogd")
11
+ has_line_in_file("local0.* /var/log/haproxy.log", "/etc/syslog.conf", {:notify => 'Service["sysklogd"]'})
12
+
13
+ # Restart sysklogd after we update the haproxy.log
14
+ has_service(:name => "sysklogd") do
15
+ ensures "running"
16
+ end
17
+
18
+ # Service is required
19
+ has_service(:name => "#{name}")
20
+
21
+ # Tempalte variables
22
+ variable(:name => "name", :value => "#{name}")
23
+ variable(:name => "nodenames", :value => list_of_node_names)
24
+ variable(:name => "node_ips", :value => list_of_node_ips)
25
+ variable(:name => "ports", :value => ([port].flatten || [Base.port].flatten))
26
+ variable(:name => "forwarding_port", :value => (forwarding_port || Base.forwarding_port))
27
+ variable(:name => "proxy_mode", :value => (proxy_mode || Base.proxy_mode))
28
+
29
+ # These can also be passed in via hash
30
+ has_remotefile(:name => "/etc/haproxy.cfg") do
31
+ mode 644
32
+ requires 'Package["haproxy"]'
33
+ notify 'Service["haproxy"]'
34
+ template File.join(File.dirname(__FILE__), "..", "templates/haproxy.conf")
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ module PoolParty
2
+ class Base
3
+ plugin :heartbeat do
4
+
5
+ def enable
6
+ has_package(:name => "heartbeat-2", :ensure => "installed")
7
+ has_service(:name => "heartbeat", :hasstatus => true) do
8
+ ensures "running"
9
+ end
10
+
11
+ has_exec(:name => "heartbeat-update-cib", :command => "/usr/sbin/cibadmin -R -x /etc/ha.d/cib.xml", :refreshonly => true)
12
+
13
+ # variables for the templates
14
+ has_variable({:name => "nodenames", :value => list_of_node_names})
15
+ has_variable({:name => "node_ips", :value => list_of_node_ips})
16
+ has_variable({:name => "port", :value => (port || Base.port)})
17
+
18
+ # These can also be passed in via hash
19
+ has_remotefile(:name => "/etc/ha.d/ha.cf") do
20
+ mode 444
21
+ requires 'Package["heartbeat-2"]'
22
+ notify 'Service["heartbeat"]'
23
+ template File.join(File.dirname(__FILE__), "..", "templates/ha.cf")
24
+ end
25
+
26
+ has_remotefile(:name => "/etc/ha.d/authkeys") do
27
+ mode 400
28
+ requires 'Package["heartbeat-2"]'
29
+ notify 'Service["heartbeat"]'
30
+ template File.join(File.dirname(__FILE__), "..", "templates/authkeys")
31
+ end
32
+
33
+ has_remotefile(:name => "/etc/ha.d/cib.xml") do
34
+ mode 444
35
+ requires 'Package["heartbeat-2"]'
36
+ notify 'Exec["heartbeat-update-cib"]'
37
+ template File.join(File.dirname(__FILE__), "..", "templates/cib.xml")
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ module PoolParty
2
+ class Base
3
+ plugin :poolparty do
4
+
5
+ def enable
6
+ has_package(:name => "erlang")
7
+ has_gem_package(:name => "auser-poolparty", :source => "http://gems.github.com")
8
+
9
+ # Build hostsfile
10
+ # TODO: COME BACK AND CLEAN THIS UP
11
+ (self.respond_to?(:remote_instances_list) ? self : parent).remote_instances_list.each do |ri|
12
+ has_host({:name => "#{ri.name}", :ip => ri.ip })
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module PoolParty
2
+ class Base
3
+ plugin :ruby do
4
+
5
+ def enable
6
+ has_package(:name => "libreadline-ruby1.8")
7
+ has_package(:name => "libruby1.8")
8
+ has_package(:name => "ruby1.8-dev")
9
+ has_package(:name => "ruby1.8")
10
+ has_package(:name => "rubygems")
11
+ end
12
+
13
+ def enable_ri
14
+ has_package(:name => "ri1.8")
15
+ end
16
+
17
+ def enable_irb
18
+ has_package(:name => "irb1.8")
19
+ end
20
+
21
+ def enable_rdoc
22
+ has_package(:name => "rdoc1.8")
23
+ end
24
+
25
+ end
26
+ end
27
+ 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
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,34 @@
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}/**"].each do |file|
14
+ File.directory?(file) ? load_p(file) : (require "#{file}")
15
+ end
16
+ end
17
+ def with_warnings_suppressed
18
+ saved_verbosity = $-v
19
+ $-v = nil
20
+ yield
21
+ ensure
22
+ $-v = saved_verbosity
23
+ end
24
+ def hide_output
25
+ begin
26
+ old_stdout = STDOUT.dup
27
+ STDOUT.reopen(File.open((PLATFORM =~ /mswin/ ? "NUL" : "/dev/null"), 'w'))
28
+ yield if block_given?
29
+ ensure
30
+ STDOUT.flush
31
+ STDOUT.reopen(old_stdout)
32
+ end
33
+ end
34
+ 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