Sha256: 28954e15e30d3dfc8e781f97cffb9c9fa1a161250f5ac0a01947d87678a69cb5

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

class Skyline::Tag < ActiveRecord::Base
  set_table_name :skyline_tags
  
  cattr_accessor :taggable_models

  before_validation :sanitize_tag  
  
  class << self
    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
    
    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
    
    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
  end
  
  protected
  
  def sanitize_tag
    self.tag = self.tag.to_s.strip.downcase if self.tag
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
skylinecms-3.2.0 app/models/skyline/tag.rb
skylinecms-3.1.0 app/models/skyline/tag.rb
westarete-skylinecms-3.0.8.20100329 app/models/skyline/tag.rb
westarete-skylinecms-3.0.8.20100330 app/models/skyline/tag.rb
skylinecms-3.0.8 app/models/skyline/tag.rb
skylinecms-3.0.7 app/models/skyline/tag.rb