Module: SemanticallyTaggable::Taggable
- Defined in:
- lib/semantically_taggable/semantically_taggable.rb,
lib/semantically_taggable/semantically_taggable/core.rb,
lib/semantically_taggable/semantically_taggable/cache.rb,
lib/semantically_taggable/semantically_taggable/collection.rb
Defined Under Namespace
Modules: Cache, Collection, Core
Instance Method Summary collapse
-
#semantically_taggable(*scheme_names) ⇒ Object
Make a model taggable in a specified scheme.
- #taggable? ⇒ Boolean
Instance Method Details
#semantically_taggable(*scheme_names) ⇒ Object
Make a model taggable in a specified scheme.
Example:
class User < ActiveRecord::Base
semantically_taggable :languages, :skills
end
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/semantically_taggable/semantically_taggable.rb', line 16 def semantically_taggable(*scheme_names) scheme_names = scheme_names.to_a.flatten.compact.map(&:to_sym) raise ArgumentError, "At least one scheme name required, none given" unless scheme_names.present? if taggable? write_inheritable_attribute(:scheme_names, (self.scheme_names + scheme_names).uniq) else write_inheritable_attribute(:scheme_names, scheme_names) class_inheritable_reader(:scheme_names) class_eval do has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "SemanticallyTaggable::Tagging" has_many :base_tags, :through => :taggings, :source => :tag, :class_name => "SemanticallyTaggable::Tag" def self.taggable? true end include SemanticallyTaggable::Taggable::Core include SemanticallyTaggable::Taggable::Collection # TODO: reintroduce caching support # include SemanticallyTaggable::Taggable::Cache end end end |
#taggable? ⇒ Boolean
3 4 5 |
# File 'lib/semantically_taggable/semantically_taggable.rb', line 3 def taggable? false end |