Sha256: f1cb38938421a8db3eede80fececc7d8c0c14472446c2b0d9450c36483aea235

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 Bytes

Contents

class Bastet::Group
  attr_accessor :name, :criteria

  def initialize name, &block
    raise ArgumentError.new("Need to pass a criteria") unless block_given?
    validate_name!(name.to_s)

    @name = name.to_s
    @criteria = block

    persist!
  end

  def self.find name
    Bastet.groups.detect { |group| group.name == name }
  end

  def contains? entity
    criteria.call(entity) rescue false
  end

  private

    def validate_name! name
      if Bastet::Group.find(name)
        raise ArgumentError.new("#{name} is already initialized as a group.")
      end
    end

    def persist!
      Bastet.groups << self
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bastet-0.1.2 lib/bastet/group.rb