Module: Redmineup::ActsAsTaggable::Taggable::ClassMethods
- Defined in:
- lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb
Instance Method Summary collapse
- #cached_tag_list_column_name ⇒ Object
-
#create_taggable_table(options = {}) ⇒ Object
Create the taggable tables === Options hash: *
:table_name
- use a table name other than viewings To be used during migration, but can also be used in other places. - #drop_taggable_table(options = {}) ⇒ Object
- #set_cached_tag_list_column_name(value = nil, &block) ⇒ Object
- #taggable? ⇒ Boolean
- #up_acts_as_taggable ⇒ Object
Instance Method Details
#cached_tag_list_column_name ⇒ Object
37 38 39 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 37 def cached_tag_list_column_name 'cached_tag_list' end |
#create_taggable_table(options = {}) ⇒ Object
Create the taggable tables
Options hash:
-
:table_name
- use a table name other than viewings
To be used during migration, but can also be used in other places
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 49 def create_taggable_table( = {}) tag_name_table = [:tags] || :tags if !self.connection.table_exists?(tag_name_table) self.connection.create_table(tag_name_table) do |t| t.column :name, :string end end taggings_name_table = [:taggings] || :taggings if !self.connection.table_exists?(taggings_name_table) self.connection.create_table(taggings_name_table) do |t| t.column :tag_id, :integer t.column :taggable_id, :integer # You should make sure that the column created is # long enough to store the required class names. t.column :taggable_type, :string t.column :created_at, :datetime end self.connection.add_index :taggings, :tag_id self.connection.add_index :taggings, [:taggable_id, :taggable_type] end end |
#drop_taggable_table(options = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 76 def drop_taggable_table( = {}) tag_name_table = [:tags] || :tags if self.connection.table_exists?(tag_name_table) self.connection.drop_table tag_name_table end taggings_name_table = [:taggings] || :taggings if self.connection.table_exists?(taggings_name_table) self.connection.drop_table taggings_name_table end end |
#set_cached_tag_list_column_name(value = nil, &block) ⇒ Object
41 42 43 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 41 def set_cached_tag_list_column_name(value = nil, &block) define_attr_method :cached_tag_list_column_name, value, &block end |
#taggable? ⇒ Boolean
11 12 13 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 11 def taggable? false end |
#up_acts_as_taggable ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 15 def up_acts_as_taggable has_many :taggings, :as => :taggable, :dependent => :destroy, :class_name => '::Redmineup::ActsAsTaggable::Tagging' has_many :tags, :through => :taggings, :class_name => '::Redmineup::ActsAsTaggable::Tag' before_save :save_cached_tag_list after_create :save_tags after_update :save_tags include Redmineup::ActsAsTaggable::Taggable::InstanceMethods extend Redmineup::ActsAsTaggable::Taggable::SingletonMethods alias_method :reload_without_tag_list, :reload alias_method :reload, :reload_with_tag_list class_eval do def self.taggable? true end end end |