Sha256: 6d167b0591b372b50de47585041d57eed056c2b5d0d9e25457f0d18d461af44b

Contents?: true

Size: 655 Bytes

Versions: 2

Compression:

Stored size: 655 Bytes

Contents

class Hadouken::Groups
  include Enumerable

  def initialize
    @groups = {}
    @order  = []
  end

  def count
    @groups.values.size
  end
  alias :size :count

  def hosts
    @groups.values.map{|group| group.hosts}.flatten
  end

  def each
    @order.uniq!
    @order.each do |name|
      yield @groups[name]
    end
  end

  def [](name)
    fetch name
  end

  def fetch (name)
    @groups[ name ]
  end

  def add (name, opts)
    store(Hadouken::Group.create!(name, opts))
  end

  def store (group)
    raise ArgumentError.new("8==D~") unless group.is_a?(Hadouken::Group)
    @groups[ group.name ] = group
    @order << group.name
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hadouken-0.1.5.pre lib/hadouken/groups.rb
hadouken-0.1.4.pre lib/hadouken/groups.rb