Module HasMachineTags::ClassMethods

  1. lib/has_machine_tags.rb

Methods

public instance

  1. has_machine_tags

Public instance methods

has_machine_tags (options={})

Options:

:console
When true, adds additional helper methods from HasMachineTags::Console to use mainly in irb.
:reverse_has_many
Defines a has_many :through from tags to the model using the plural of the model name.
:quick_mode
When true, enables a quick mode to input machine tags with HasMachineTags::InstanceMethods.tag_list=(). See examples at HasMachineTags::TagList.new().
[show source]
# File lib/has_machine_tags.rb, line 17
    def has_machine_tags(options={})
      cattr_accessor :quick_mode
      self.quick_mode = options[:quick_mode] || false
      self.class_eval do
        has_many :taggings, :as=>:taggable, :dependent=>:destroy
        has_many :tags, :through=>:taggings
        after_save :save_tags
        
        include HasMachineTags::InstanceMethods
        extend HasMachineTags::Finder
        if options[:console]
          include HasMachineTags::Console::InstanceMethods
          extend HasMachineTags::Console::ClassMethods
        end
        if respond_to?(:named_scope)
          named_scope :tagged_with, lambda{ |*args|
            find_options_for_tagged_with(*args)
          }
        end
      end
      if options[:reverse_has_many]
        model = self.to_s
        'Tag'.constantize.class_eval do
          has_many(model.tableize, :through => :taggings, :source => :taggable, :source_type =>model)
        end
      end
    end