Skip to content

Commit

Permalink
let people deviate from the only sensible tag delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haran committed Feb 8, 2009
1 parent a754071 commit cde8678
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/is_taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

module IsTaggable
class TagList < Array
cattr_accessor :delimiter
@@delimiter = ', '

def initialize(list)
list = list.is_a?(Array) ? list : list.split(@@delimiter)
super
end

def to_s
join(', ')
end
Expand Down Expand Up @@ -38,7 +46,7 @@ def self.included(klass)

module InstanceMethods
def set_tag_list(kind, list)
tag_list = TagList.new(list.is_a?(Array) ? list : list.split(', '))
tag_list = TagList.new(list)
instance_variable_set(tag_list_name_for_kind(kind), tag_list)
end

Expand Down
7 changes: 7 additions & 0 deletions test/is_taggable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
n = Comment.new :tag_list => "is_taggable, has 'tags' by default"
n.tag_list
end

expect ["one", "two"] do
IsTaggable::TagList.delimiter = " "
n = Comment.new :tag_list => "one two"
IsTaggable::TagList.delimiter = ", " # puts things back to avoid breaking following tests
n.tag_list
end

expect ["something cool", "something else cool"] do
p = Post.new :tag_list => "something cool, something else cool"
Expand Down

0 comments on commit cde8678

Please sign in to comment.