Sha256: 4208b102356118edcf1a6d61b29a2bb89932c0df8761f83e3cd417d4e00bf528

Contents?: true

Size: 783 Bytes

Versions: 1

Compression:

Stored size: 783 Bytes

Contents

Class MyTags::TagList

  include Enumerable

  def initialize(taggable)
    @taggable = taggable
  end

  def to_a
    taggable.tags.collect &:name
  end

  def <<(name)
    tag = MyTags::Tag.where(:name => name).first_or_create
    taggable.tags << tag
  end

  def delete(name)
    taggable.tags.delete MyTags::Tag.where(:name => name).first
  end

  def +(array)
    array.each { |name| self.<< name }
    self
  end

  def -(array)
    array.each { |name| self.delete name }
    self
  end

  def self.new_with_names(taggable, names)
    tag_names = new(taggable)
    tag_names.clear
    names.each { |name| tag_names << name }
    tag_names
  end

  def clear
    taggable.tags.clear
  end

  def each(&block)
    to_a.each &block
  end

  private

  attr_reader :taggable
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
my_tags-0.0.4 lib/my_tags/tag_list.rb