Sha256: e9873531c7a935b9238befc5610a0fab1d7add8c361c11ae217c3b9fd9c16bc5

Contents?: true

Size: 772 Bytes

Versions: 1

Compression:

Stored size: 772 Bytes

Contents

module TagPanda::ActiveRecord
  def self.included(base)
    # include our class methods
    base.extend TagPanda::ActiveRecord::ClassMethods
  end

  def tag_names
    @tag_names ||= TagPanda::TagNames.new self
  end

  def tag_names=(names)
    if names.is_a?(TagPanda::TagNames)
      @tag_names = names
    else
      # convert the array of strings to a TagNames object
      @tag_names = TagPanda::TagNames.new_with_names self, names
    end
  end

  module ClassMethods
    # Set up the underlying tag associations in the model
    def has_many_tags
      has_many :taggings, :class_name => 'TagPanda::Tagging',
        :as => :taggable, :dependent => :destroy
      has_many :tags,     :class_name => 'TagPanda::Tag',
        :through => :taggings
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tag_panda-0.1.0 lib/tag_panda/active_record.rb