Skip to content

Commit

Permalink
Merge pull request #33 from ancorgs/push_volume_list
Browse files Browse the repository at this point in the history
Add push (<<) method to PlannedVolumesList
  • Loading branch information
ancorgs committed Mar 23, 2016
2 parents b4ffc5f + b60c496 commit 45ae62d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/lib/storage/planned_volumes_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ module Storage
# PlannedVolume elements
class PlannedVolumesList
include Enumerable
extend Forwardable

def initialize(volumes = [])
@volumes = volumes
end

def each(&block)
@volumes.each(&block)
end
def_delegators :@volumes, :each, :empty?, :length, :size

def dup
PlannedVolumesList.new(@volumes.dup)
Expand Down Expand Up @@ -78,21 +77,6 @@ def total_weight
@volumes.reduce(0.0) { |sum, vol| sum + vol.weight }
end

# Returns true if the list contains no elements
#
# @return [Boolean]
def empty?
@volumes.empty?
end

# Number of elements in the list
#
# @return [Fixnum]
def length
@volumes.length
end
alias_method :size, :length

# Deletes every element of the list for which block evaluates to true
#
# If no block is given, it returns an Enumerator
Expand All @@ -102,6 +86,17 @@ def delete_if(&block)
delegated = @volumes.delete_if(&block)
delegated.is_a?(Array) ? PlannedVolumesList.new(delegated) : delegated
end

# Appends the given volume to the list. It returns the list itself,
# so several appends may be chained together
#
# @param volume [PlannedVolume] element to add
# @return [PlannedVolumesList]
def push(volume)
@volumes.push(volume)
self
end
alias_method :<<, :push
end
end
end

0 comments on commit 45ae62d

Please sign in to comment.