Class: RocketTag::Taggable::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket_tag/taggable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Manager

Returns a new instance of Manager.


52
53
54
55
56
# File 'lib/rocket_tag/taggable.rb', line 52

def initialize klass
  @klass = klass
  @contexts = Set.new
  setup_relations
end

Instance Attribute Details

#contextsObject

Returns the value of attribute contexts


30
31
32
# File 'lib/rocket_tag/taggable.rb', line 30

def contexts
  @contexts
end

#klassObject (readonly)

Returns the value of attribute klass


32
33
34
# File 'lib/rocket_tag/taggable.rb', line 32

def klass
  @klass
end

Class Method Details

.parse_tags(list) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rocket_tag/taggable.rb', line 34

def self.parse_tags list
  require 'csv'
  if list.kind_of? String
    # for some reason CSV parser cannot handle
    #     
    #     hello, "foo"
    #
    # but must be
    #
    #     hello,"foo"
    return [] if list.empty?
    list = list.gsub /,\s+"/, ',"'
    list = list.parse_csv.map &:strip
  else
    list
  end
end

Instance Method Details

#setup_relationsObject


58
59
60
61
# File 'lib/rocket_tag/taggable.rb', line 58

def setup_relations
  klass.has_many :taggings , :dependent => :destroy , :as => :taggable, :class_name => "RocketTag::Tagging"
  klass.has_many :tags     , :source => :tag, :through => :taggings, :class_name => "RocketTag::Tag"
end