Class: Warg::HostCollection
- Inherits:
-
Object
- Object
- Warg::HostCollection
show all
- Includes:
- Enumerable, Interaction
- Defined in:
- lib/warg.rb
Defined Under Namespace
Modules: Interaction
Class Method Summary
collapse
Instance Method Summary
collapse
#create_file_from, #download, #run, #run_command, #run_script, #upload
Constructor Details
Returns a new instance of HostCollection.
1126
1127
1128
|
# File 'lib/warg.rb', line 1126
def initialize
@hosts = []
end
|
Class Method Details
.from(value) ⇒ Object
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
|
# File 'lib/warg.rb', line 1085
def self.from(value)
case value
when String, Host
new.add(value)
when HostCollection
value
when Array
is_array_host_specification = value.any? do |item|
String === item and item.index("=") and not item.index("?")
end
if is_array_host_specification
new.add(value)
else
value.inject(new) { |collection, host_data| collection.add(host_data) }
end
when Hash
value.inject(new) do |collection, (property, hosts_data)|
name, value = property.to_s.split(":", 2)
if value.nil?
value = name
name = "stage"
end
from(hosts_data).each do |host|
host[name] = value
collection.add(host)
end
collection
end
when nil
new
else
raise InvalidHostDataError.new(value)
end
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
1148
1149
1150
1151
1152
1153
1154
|
# File 'lib/warg.rb', line 1148
def ==(other)
self.class == other.class &&
length == other.length &&
length == @hosts.&(other.hosts).length
end
|
#add(host_data) ⇒ Object
1138
1139
1140
1141
1142
|
# File 'lib/warg.rb', line 1138
def add(host_data)
@hosts << Host.from(host_data)
self
end
|
#each ⇒ Object
1166
1167
1168
1169
1170
1171
1172
1173
1174
|
# File 'lib/warg.rb', line 1166
def each
if block_given?
@hosts.each { |host| yield host }
else
enum_for(:each)
end
self
end
|
#length ⇒ Object
1158
1159
1160
|
# File 'lib/warg.rb', line 1158
def length
@hosts.length
end
|
#one ⇒ Object
1130
1131
1132
1133
1134
1135
1136
|
# File 'lib/warg.rb', line 1130
def one
if @hosts.empty?
raise "cannot pick a host from `#{inspect}'; collection is empty"
end
HostCollection.from @hosts.sample
end
|
#to_a ⇒ Object
1216
1217
1218
|
# File 'lib/warg.rb', line 1216
def to_a
@hosts.dup
end
|
#with(**filters) ⇒ Object
1144
1145
1146
|
# File 'lib/warg.rb', line 1144
def with(**filters)
HostCollection.from(select { |host| host.matches?(**filters) })
end
|