Class: Skyline::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/skyline/tag.rb

Class Method Summary collapse

Class Method Details

.delete_unused_tagsObject



24
25
26
# File 'app/models/skyline/tag.rb', line 24

def delete_unused_tags
  self.connection.execute("DELETE FROM #{self.table_name} WHERE id NOT IN (SELECT DISTINCT tag_id FROM #{Skyline::AssociatedTag.table_name})")
end

.register_taggable_model(klass) ⇒ Object



18
19
20
21
22
# File 'app/models/skyline/tag.rb', line 18

def register_taggable_model(klass)
  self.taggable_models ||= []
  self.taggable_models.delete_if{|c| c.to_s == klass.to_s } # Hack to remove stale object
  self.taggable_models << klass      
end

.taggable_content_modelsObject



9
10
11
12
13
14
15
16
# File 'app/models/skyline/tag.rb', line 9

def taggable_content_models
  # lazy load all models in /app/models (not recursive) to find all Content models
  Dir.chdir(File.join(Rails.root, "app", "models")) do 
    Dir.glob("*.rb").map{|f| f.sub(".rb","").camelcase.constantize}
  end

  (taggable_models || []).delete_if{|m| m.parents.include?(Skyline) } 
end