Class: Models::Tags

Inherits:
Array
  • Object
show all
Defined in:
lib/kit/models/tags.rb

Defined Under Namespace

Classes: ContextTags

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array = nil) ⇒ Tags

Returns a new instance of Tags.



4
5
6
7
# File 'lib/kit/models/tags.rb', line 4

def initialize array = nil
  super()
  replace array if array
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &b) ⇒ Object (protected)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kit/models/tags.rb', line 42

def method_missing m, *args, &b
  if m !~ /=$/
    context = m.to_s
    args.size.must == 0
    get_tags{|tag| tag =~ /#{context}:/}
  else
    context = m.to_s[0..-2]
    args.size.must == 1
    value = args.first
    set_tags(value){|tag| tag =~ /#{context}:/}
  end
end

Instance Attribute Details

#_changesObject

Updating Tag and counts cache



28
29
30
# File 'lib/kit/models/tags.rb', line 28

def _changes
  @_changes
end

Instance Method Details

#as_stringObject



23
# File 'lib/kit/models/tags.rb', line 23

def as_string; join(", ") end

#topicObject



16
17
18
# File 'lib/kit/models/tags.rb', line 16

def topic
  get_tags{|tag| tag !~ /:/}
end

#topic=(value) ⇒ Object



19
20
21
# File 'lib/kit/models/tags.rb', line 19

def topic= value
  set_tags(value){|tag| tag !~ /:/}
end