Sha256: db28cea8a3b024bc9de3f07c8e534e1abf6563b50a828f0eac71cb9e4a286592

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

class MyTags::Tags

  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.3 lib/my_tags/tags.rb