Class: Rye::Set
- Inherits:
-
Object
- Object
- Rye::Set
- Defined in:
- lib/rye/set.rb
Overview
Rye::Set
Instance Attribute Summary collapse
-
#boxes ⇒ Object
readonly
Returns the value of attribute boxes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#[](key = nil) ⇒ Object
See Rye::Box.[].
-
#add_box(*boxes) ⇒ Object
(also: #add_boxes)
-
boxes
one or more boxes.
-
-
#add_env(n, v) ⇒ Object
(also: #add_environment_variable)
Add an environment variable.
-
#add_key(*additional_keys) ⇒ Object
(also: #add_keys)
Add one or more private keys to the SSH Agent.
-
#cd(key = nil) ⇒ Object
alias :cd :‘[]’ # fix for jruby.
-
#initialize(name = 'default', opts = {}) ⇒ Set
constructor
-
name
The name of the set of machines *opts
a hash of optional arguments .
-
- #inspect ⇒ Object
-
#keys ⇒ Object
See Rye.keys.
-
#method_missing(meth, *args) ⇒ Object
Catches calls to Rye::Box commands.
- #to_s ⇒ Object
Constructor Details
#initialize(name = 'default', opts = {}) ⇒ Set
-
name
The name of the set of machines -
opts
a hash of optional arguments
The opts
hash is used as defaults for all for all Rye::Box objects. All args supported by Rye::Box are available here with the addition of:
-
:parallel => run the commands in parallel? true or false (default).
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rye/set.rb', line 19 def initialize(name='default', opts={}) @name = name @boxes = [] # These opts are use by Rye::Box and also passed to Net::SSH @opts = { :parallel => false, :user => Rye.sysinfo.user, :safe => true, :port => 22, :keys => [], :password => nil, :proxy => nil, :debug => nil, :error => STDERR, }.merge(opts) @parallel = @opts.delete(:parallel) # Rye::Box doesn't have :parallel @safe = @opts.delete(:safe) @debug = @opts.delete(:debug) @error = @opts.delete(:error) add_keys(@opts[:keys]) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Catches calls to Rye::Box commands. If meth
is the name of an instance method defined in Rye::Cmd then we call it against all the boxes in @boxes. Otherwise this method raises a Rye::CommandNotFound exception. It will also raise a Rye::NoBoxes exception if this set has no boxes defined.
Returns a Rye::Rap object containing the responses from each Rye::Box.
108 109 110 111 112 113 114 |
# File 'lib/rye/set.rb', line 108 def method_missing(meth, *args) # Ruby 1.8 populates Module.instance_methods with Strings. 1.9 uses Symbols. meth = (Rye.sysinfo.ruby[1] == 8) ? meth.to_s : meth.to_sym raise Rye::NoBoxes if @boxes.empty? raise Rye::CommandNotFound, meth.to_s unless Rye::Cmd.instance_methods.member?(meth) run_command(meth, *args) end |
Instance Attribute Details
#boxes ⇒ Object (readonly)
Returns the value of attribute boxes.
8 9 10 |
# File 'lib/rye/set.rb', line 8 def boxes @boxes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rye/set.rb', line 7 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
9 10 11 |
# File 'lib/rye/set.rb', line 9 def opts @opts end |
Instance Method Details
#[](key = nil) ⇒ Object
See Rye::Box.[]
91 92 93 94 |
# File 'lib/rye/set.rb', line 91 def [](key=nil) run_command(:cd, key) self end |
#add_box(*boxes) ⇒ Object Also known as: add_boxes
-
boxes
one or more boxes. Rye::Box objects will be added directly
to the set. Hostnames will be used to create new instances of Rye::Box and those will be added to the list.
48 49 50 51 52 53 54 55 56 |
# File 'lib/rye/set.rb', line 48 def add_box(*boxes) boxes = boxes.flatten.compact @boxes += boxes.collect do |box| b = box.is_a?(String) ? Rye::Box.new(box, @opts) : box b.add_keys(@keys) b end self end |
#add_env(n, v) ⇒ Object Also known as: add_environment_variable
Add an environment variable. n
and v
are the name and value. Returns the instance of Rye::Set
71 72 73 74 |
# File 'lib/rye/set.rb', line 71 def add_env(n, v) run_command(:add_env, n, v) self end |
#add_key(*additional_keys) ⇒ Object Also known as: add_keys
Add one or more private keys to the SSH Agent.
-
additional_keys
is a list of file paths to private keys
Returns the instance of Rye::Set
62 63 64 65 66 |
# File 'lib/rye/set.rb', line 62 def add_key(*additional_keys) additional_keys = [additional_keys].flatten.compact || [] Rye.add_keys(additional_keys) self end |
#cd(key = nil) ⇒ Object
alias :cd :‘[]’ # fix for jruby
96 97 98 99 |
# File 'lib/rye/set.rb', line 96 def cd(key=nil) run_command(:cd, key) self end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/rye/set.rb', line 86 def inspect %q{#<%s:%s boxes=%s opts=%s>} % [self.class.to_s, self.name, self.boxes.join(','), self.opts.inspect] end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/rye/set.rb', line 82 def to_s "%s: %s" % [self.name, ] end |