Class: TagDb::Model::Tag

Inherits:
ActiveRecord::Base show all
Defined in:
lib/tagutils/tags/models/tag.rb,
lib/tagutils/tags/models/tag_comp.rb

Instance Method Summary collapse

Methods included from ClassMacros

#has_many_tags

Methods included from CategoryDb::ClassMacros

#has_many_categories

Instance Method Details

#keyObject

nb: only allow spaces and underscore inbetween;

do NOT allow digit as first char for now


12
13
# File 'lib/tagutils/tags/models/tag.rb', line 12

validates :key,  :format => { :with    => /^([a-z]|[a-z][a-z0-9_ ]*[a-z0-9])$/,
:message => 'expected one or more lowercase letters a-z or 0-9 digits or space or underscore' }

#on_before_saveObject



22
23
24
25
26
27
28
# File 'lib/tagutils/tags/models/tag.rb', line 22

def on_before_save
  # replace space with dash e.g. north america becomes north_america and so on
  self.slug = key.gsub( ' ', '_' )

  ## if name is empty auto fill w/ key
  self.name = key   if name.blank?
end

#titleObject

alias for name (depreciated api calls)



11
# File 'lib/tagutils/tags/models/tag_comp.rb', line 11

def title()       name;              end

#title=(value) ⇒ Object



12
# File 'lib/tagutils/tags/models/tag_comp.rb', line 12

def title=(value) self.name = value; end