Class: RocketTag::Taggable::Manager
- Inherits:
-
Object
- Object
- RocketTag::Taggable::Manager
- Defined in:
- lib/rocket_tag/taggable.rb
Instance Attribute Summary collapse
-
#contexts ⇒ Object
Returns the value of attribute contexts.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass) ⇒ Manager
constructor
A new instance of Manager.
- #setup_relations ⇒ Object
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
#contexts ⇒ Object
Returns the value of attribute contexts.
30 31 32 |
# File 'lib/rocket_tag/taggable.rb', line 30 def contexts @contexts end |
#klass ⇒ Object (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. 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_relations ⇒ Object
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 |