Class: Object

Inherits:
BasicObject
Includes:
PoolParty, PoolParty::Cloud, PoolParty::Console, PoolParty::DefinableResource, PoolParty::Pool
Defined in:
lib/poolparty/core/object.rb,
lib/poolparty.rb,
lib/poolparty/net/init.rb,
lib/poolparty/helpers/console.rb

Overview

Basic, add an alias_method to the object class

Add returning to the object

Instance Method Summary collapse

Methods included from PoolParty::Console

#help, #reload!

Methods included from PoolParty::DefinableResource

#define_resource, #virtual_resource

Methods included from PoolParty::Cloud

#cloud, #clouds, #with_cloud

Methods included from PoolParty::Pool

#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!

Methods included from PoolParty::Remote

#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

Methods included from PoolParty::Pinger

included

Methods included from PoolParty::FileWriter

#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

#debuggingObject



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

Returns:

  • (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

#meta_def(name, &blk) ⇒ Object



68
69
70
# File 'lib/poolparty/core/object.rb', line 68

def meta_def name, &blk
  meta_eval { define_method name, &blk }
end

#meta_undef(name) ⇒ Object



71
72
73
# File 'lib/poolparty/core/object.rb', line 71

def meta_undef name
  meta_eval { remove_method name }
end

#metaclassObject

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_methodsObject



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_basesObject

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_stringObject



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

Yields:

  • (receiver)


20
21
22
23
# File 'lib/poolparty/core/object.rb', line 20

def returning(receiver)
  yield receiver
  receiver
end

#run_procsObject

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

#thisObject



9
10
11
# File 'lib/poolparty/core/object.rb', line 9

def this
  self
end

#to_osObject



12
13
14
# File 'lib/poolparty/core/object.rb', line 12

def to_os
  self
end

#unix_hide_stringObject



108
109
110
# File 'lib/poolparty/core/object.rb', line 108

def unix_hide_string
  "2>&1 > /dev/null"
end

#verbose?(o = self) ⇒ Boolean

Returns:

  • (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 m if o.verbose rescue ""
  puts "[INFO] -- #{m}" if verbose?
end