diff --git a/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb b/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb index cc48c64..b612984 100755 --- a/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb +++ b/lib/aws-missing-tools/aws-ha-release/aws-ha-release.rb @@ -98,7 +98,7 @@ module AwsMissingTools @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}" - @group.auto_scaling_instances.each_slice(@opts[:num_simultaneous_instances]) do |instances| + @group.auto_scaling_instances.to_a.each_slice(@opts[:num_simultaneous_instances]) do |instances| time_taken = 0 until all_instances_inservice_for_time_period?(@group.load_balancers, INSERVICE_POLLING_TIME) diff --git a/spec/support/fake_auto_scaling.rb b/spec/support/fake_auto_scaling.rb index 6fe7aa1..30dcae6 100644 --- a/spec/support/fake_auto_scaling.rb +++ b/spec/support/fake_auto_scaling.rb @@ -48,7 +48,7 @@ module AWS end def auto_scaling_instances - @auto_scaling_instances ||= [AWS::FakeAutoScaling::Instance.new(self), AWS::FakeAutoScaling::Instance.new(self)] + @auto_scaling_instances ||= AWS::FakeCore::Data::List.new [AWS::FakeAutoScaling::Instance.new(self), AWS::FakeAutoScaling::Instance.new(self)] end def load_balancers diff --git a/spec/support/fake_core_data_list.rb b/spec/support/fake_core_data_list.rb new file mode 100644 index 0000000..e23c996 --- /dev/null +++ b/spec/support/fake_core_data_list.rb @@ -0,0 +1,71 @@ +module AWS + module FakeCore + class Data + module MethodMissingProxy + + protected + + def method_missing *args, &block + if block_given? + return_value = @data.send(*args) do |*values| + yield(*values.flatten.map{|v| Data.cast(v) }) + end + Data.cast(return_value) + else + Data.cast(@data.send(*args)) + end + end + + end + + include MethodMissingProxy + + def method_missing method_name, *args, &block + if + args.empty? and !block_given? and + key = _remove_question_mark(method_name) and + @data.has_key?(key) + then + Data.cast(@data[key]) + else + super + end + end + + class << self + + # Given a hash, this method returns a {Data} object. Given + # an Array, this method returns a {Data::List} object. Everything + # else is returned as is. + # + # @param [Object] value The value to conditionally wrap. + # + # @return [Data,Data::List,Object] Wraps hashes and lists with + # Data and List objects, all other objects are returned as + # is. + # + def cast value + case value + when Hash then Data.new(value) + when Array then Data::List.new(value) + else value + end + end + + end + + class List + include MethodMissingProxy + + def initialize(array) + @data = array + end + + def to_ary + @data + end + alias_method :to_a, :to_ary + end + end + end +end