Class: Object
Overview
Basic, add an alias_method to the object class
Add returning to the object
Instance Method Summary
collapse
-
#alias_method(new_id, original_id) ⇒ Object
-
#block_instance_eval(*args, &block) ⇒ Object
-
#class_eval(*args, &block) ⇒ Object
If class_eval is called on an object, add those methods to its metaclass from activesupport.
-
#debugging ⇒ Object
-
#debugging=(bool) ⇒ Object
-
#debugging?(o = self) ⇒ Boolean
-
#do_once(&block) ⇒ Object
-
#dprint(m = "", o = self) ⇒ Object
-
#dputs(m = "", o = self) ⇒ Object
-
#extended(&block) ⇒ Object
-
#meta_def(name, &blk) ⇒ Object
-
#meta_undef(name) ⇒ Object
-
#metaclass ⇒ Object
Get object’s meta (ghost, eigenclass, singleton) class from activesupport.
-
#my_methods ⇒ Object
-
#remote_bases ⇒ Object
-
#respec_string ⇒ Object
-
#returning(receiver) {|receiver| ... } ⇒ Object
-
#run_procs ⇒ Object
Procs that have been run already in the run_once blocks This is just a container array of procs.
-
#testing(bool = $TESTING) ⇒ Object
-
#this ⇒ Object
-
#to_os ⇒ Object
-
#unix_hide_string ⇒ Object
-
#verbose?(o = self) ⇒ Boolean
-
#vprint(m = "", o = self) ⇒ Object
-
#vputs(m = "", o = self) ⇒ Object
def run_in_context(context=self, &block) name=“temp_#selfself.class_#? parent.to_s : Time.now.to_i”.to_sym meta_def name, &block self.send name, context meta_undef name rescue “” end.
#help, #reload!
#define_resource, #virtual_resource
#cloud, #clouds, #with_cloud
#pool, #pool_specfile, #pools, #remove_pool, #reset!, #set_pool_specfile, #with_pool
Methods included from PoolParty
#context_stack, #extract_cloud_from_options, #extract_pool_from_options, load_cloud_from_json, #load_pool, #log, #pack_user_directory, #pool_specfile, #print_with_nice_printer, require_directory, #require_user_directory, #reset!
#are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, available, #commands, #execute!, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #netssh, #nodes, #remote_rsync_command, #remote_ssh_array, #remote_ssh_string, #rsync, #rsync_command, #rsync_storage_files_to, #rsync_storage_files_to_command, #rsync_to, #rsync_to_command, #run_command_on, #run_command_on_command, #run_command_on_instance_number, #run_local, #run_remote, #scp_array, #scp_to_command, #simplest_run_remote, #ssh_array, #ssh_command, #ssh_into, #ssh_into_instance_number, #ssh_options, #ssh_string, #target_host
included
#cleanup_storage_directory, #clear_base_directory, #copy_directory_into_storage_directory, #copy_directory_into_template_storage_directory, #copy_file_to_storage_directory, #copy_template_to_storage_directory, #make_base_directory, #make_base_path, #make_directory_in_storage_directory, #make_template_directory, #write_to_file, #write_to_file_in_storage_directory, #write_to_temp_file
Instance Method Details
#alias_method(new_id, original_id) ⇒ Object
15
16
17
18
|
# File 'lib/poolparty/core/object.rb', line 15
def alias_method(new_id, original_id)
original = self.method(original_id).to_proc
define_method(new_id){|*args| original.call(*args)}
end
|
#block_instance_eval(*args, &block) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/poolparty/core/object.rb', line 56
def block_instance_eval(*args, &block)
return instance_eval(*args,&block) unless block && !block.arity.zero?
old_method = (self.class.instance_method(:__) rescue nil)
self.class.send(:define_method, :__, &block)
block_method = self.class.instance_method(:__)
if old_method
self.class.send(:define_method, :__, old_method)
else
self.class.send(:remove_method, :__)
end
block_method.bind(self).call(*args)
end
|
#class_eval(*args, &block) ⇒ Object
If class_eval is called on an object, add those methods to its metaclass from activesupport
122
123
124
|
# File 'lib/poolparty/core/object.rb', line 122
def class_eval(*args, &block)
metaclass.class_eval(*args, &block)
end
|
#debugging ⇒ Object
99
100
101
|
# File 'lib/poolparty/core/object.rb', line 99
def debugging
$DEBUGGING ||= false
end
|
#debugging=(bool) ⇒ Object
102
103
104
|
# File 'lib/poolparty/core/object.rb', line 102
def debugging=(bool)
$DEBUGGING = bool
end
|
#debugging?(o = self) ⇒ Boolean
96
97
98
|
# File 'lib/poolparty/core/object.rb', line 96
def debugging?(o=self)
debugging
end
|
#do_once(&block) ⇒ Object
Do once. Takes a block. IF this block has already been run (from the run_procs array), then run it and store the block unique id in the run_procs array so it never gets run again
39
40
41
42
43
44
|
# File 'lib/poolparty/core/object.rb', line 39
def do_once(&block)
unless run_procs.include?(block.to_s)
instance_eval &block if block
run_procs << block.to_s
end
end
|
#dprint(m = "", o = self) ⇒ Object
90
91
92
|
# File 'lib/poolparty/core/object.rb', line 90
def dprint(m="", o=self)
print "#{m}" if debugging?(o) || verbose?(o) rescue ""
end
|
#dputs(m = "", o = self) ⇒ Object
87
88
89
|
# File 'lib/poolparty/core/object.rb', line 87
def dputs(m="", o=self)
puts "[DEBUG] -- #{m.inspect}" if debugging?(o) rescue ""
end
|
#extended(&block) ⇒ Object
24
25
26
27
|
# File 'lib/poolparty/core/object.rb', line 24
def extended(&block)
block.in_context(self).call
self
end
|
68
69
70
|
# File 'lib/poolparty/core/object.rb', line 68
def meta_def name, &blk
meta_eval { define_method name, &blk }
end
|
71
72
73
|
# File 'lib/poolparty/core/object.rb', line 71
def meta_undef name
meta_eval { remove_method name }
end
|
Get object’s meta (ghost, eigenclass, singleton) class from activesupport
114
115
116
117
118
|
# File 'lib/poolparty/core/object.rb', line 114
def metaclass
class << self
self
end
end
|
#my_methods ⇒ Object
6
7
8
|
# File 'lib/poolparty/core/object.rb', line 6
def my_methods
self.methods.sort - (self.class.methods + self.class.superclass.methods)
end
|
#remote_bases ⇒ Object
TODO: deprecate. use RemoterBase.available_bases instead
3
4
5
|
# File 'lib/poolparty/net/init.rb', line 3
def remote_bases
PoolParty::Remote.available
end
|
#respec_string ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/poolparty/core/object.rb', line 46
def respec_string
case self.class
when String
self.to_option_string
when Array
self.map {|a| "#{a.respec_string}" }.join(" ")
else
"'#{self}'"
end
end
|
#returning(receiver) {|receiver| ... } ⇒ Object
20
21
22
23
|
# File 'lib/poolparty/core/object.rb', line 20
def returning(receiver)
yield receiver
receiver
end
|
#run_procs ⇒ Object
Procs that have been run already in the run_once blocks This is just a container array of procs
31
32
33
|
# File 'lib/poolparty/core/object.rb', line 31
def run_procs
@run_procs ||= []
end
|
#testing(bool = $TESTING) ⇒ Object
105
106
107
|
# File 'lib/poolparty/core/object.rb', line 105
def testing(bool=$TESTING)
bool.nil? ? $TESTING : $TESTING = bool
end
|
9
10
11
|
# File 'lib/poolparty/core/object.rb', line 9
def this
self
end
|
12
13
14
|
# File 'lib/poolparty/core/object.rb', line 12
def to_os
self
end
|
#unix_hide_string ⇒ Object
108
109
110
|
# File 'lib/poolparty/core/object.rb', line 108
def unix_hide_string
"2>&1 > /dev/null"
end
|
#verbose?(o = self) ⇒ Boolean
93
94
95
|
# File 'lib/poolparty/core/object.rb', line 93
def verbose?(o=self)
o.respond_to?(:verbose) ? o.verbose : (debugging? || $TESTING ||= false)
end
|
#vprint(m = "", o = self) ⇒ Object
84
85
86
|
# File 'lib/poolparty/core/object.rb', line 84
def vprint(m="", o=self)
print m if o.verbose rescue ""
end
|
#vputs(m = "", o = self) ⇒ Object
def run_in_context(context=self, &block)
name="temp_#{self.class}_#{respond_to?(:parent) ? parent.to_s : Time.now.to_i}".to_sym
meta_def name, &block
self.send name, context
meta_undef name rescue ""
end
80
81
82
83
|
# File 'lib/poolparty/core/object.rb', line 80
def vputs(m="", o=self)
puts "[INFO] -- #{m}" if verbose?
end
|